Commit d8b656ef authored by SND\ussrhero_cp's avatar SND\ussrhero_cp Committed by Mikhail I. Izmestev

added getCount to heap enum

git-svn-id: https://kdlibcpp.svn.codeplex.com/svn@91256 9b283d60-5439-405e-af05-b73fd8c4d996
parent 04cfb35a
......@@ -30,7 +30,9 @@ class TargetHeapEnum
{
public:
virtual bool Next(MEMOFFSET_64& addr, std::wstring& typeName, size_t& typeSize) = 0;
virtual bool next(MEMOFFSET_64& addr, std::wstring& typeName, size_t& typeSize) = 0;
virtual size_t getCount() const = 0;
};
TargetHeapPtr getManagedHeap();
......
......@@ -51,44 +51,7 @@ TargetHeapPtr getManagedHeap()
size_t NetHeap::getCount(const std::wstring& typeName, size_t minSize, size_t maxSize) const
{
CComPtr<ICorDebugHeapEnum> heapEnum;
HRESULT hres = g_netMgr->targetProcess5()->EnumerateHeap(&heapEnum);
if (FAILED(hres))
throw DbgException("Failed ICorDebugProcess5::EnumerateHeap");
size_t elemCount = 0;
while(true)
{
COR_HEAPOBJECT heapObj;
hres = heapEnum->Next(1, &heapObj, NULL);
if (FAILED(hres))
throw DbgException("Failed ICorDebugHeapEnum::Next");
if ( S_OK != hres )
break;
if ( !typeName.empty() || minSize != 0 || maxSize != -1 )
{
TypeInfoPtr typeObj = getNetTypeById(heapObj.type);
std::wstring tn = typeObj->getName();
if ( !typeName.empty() && !fnmatch(typeName, typeObj->getName() ))
continue;
if ( minSize != 0 && heapObj.size < minSize )
continue;
if ( maxSize != -1 && heapObj.size > maxSize )
continue;
}
elemCount++;
}
return elemCount;
return NetHeapEnum(typeName, minSize, maxSize).getCount();
}
///////////////////////////////////////////////////////////////////////////////
......@@ -112,7 +75,7 @@ NetHeapEnum::NetHeapEnum(const std::wstring& typeName, size_t minSize, size_t m
///////////////////////////////////////////////////////////////////////////////
bool NetHeapEnum::Next(MEMOFFSET_64& addr, std::wstring& typeName, size_t& size)
bool NetHeapEnum::next(MEMOFFSET_64& addr, std::wstring& typeName, size_t& size)
{
HRESULT hres;
......@@ -152,4 +115,48 @@ bool NetHeapEnum::Next(MEMOFFSET_64& addr, std::wstring& typeName, size_t& size)
///////////////////////////////////////////////////////////////////////////////
size_t NetHeapEnum::getCount() const
{
CComPtr<ICorDebugHeapEnum> heapEnum;
HRESULT hres = g_netMgr->targetProcess5()->EnumerateHeap(&heapEnum);
if (FAILED(hres))
throw DbgException("Failed ICorDebugProcess5::EnumerateHeap");
size_t elemCount = 0;
while(true)
{
COR_HEAPOBJECT heapObj;
hres = heapEnum->Next(1, &heapObj, NULL);
if (FAILED(hres))
throw DbgException("Failed ICorDebugHeapEnum::Next");
if ( S_OK != hres )
break;
if ( !m_typeMask.empty() || m_minSize != 0 || m_maxSize != -1 )
{
TypeInfoPtr typeObj = getNetTypeById(heapObj.type);
std::wstring tn = typeObj->getName();
if ( !m_typeMask.empty() && !fnmatch(m_typeMask, typeObj->getName() ))
continue;
if ( m_minSize != 0 && heapObj.size < m_minSize )
continue;
if ( m_maxSize != -1 && heapObj.size > m_maxSize )
continue;
}
elemCount++;
}
return elemCount;
}
///////////////////////////////////////////////////////////////////////////////
}
......@@ -26,9 +26,11 @@ public:
NetHeapEnum(const std::wstring& typeName=L"", size_t minSize = 0, size_t maxSize = -1);
private:
public:
virtual bool next(MEMOFFSET_64& addr, std::wstring& typeName, size_t& typeSize);
virtual bool Next(MEMOFFSET_64& addr, std::wstring& typeName, size_t& size);
virtual size_t getCount() const;
private:
......
......@@ -35,7 +35,7 @@ TEST_F(NetTest, NetHeap)
std::wstring typeName;
size_t size;
MEMOFFSET_64 address;
EXPECT_TRUE( heapEnum->Next(address, typeName, size) );
EXPECT_TRUE( heapEnum->next(address, typeName, size) );
}
//TEST_F(NetTest, NetModuleEnumTypes)
......@@ -82,7 +82,7 @@ protected:
std::wstring typeName;
size_t size;
MEMOFFSET_64 address;
ASSERT_TRUE( heapEnum->Next(address, typeName, size) );
ASSERT_TRUE( heapEnum->next(address, typeName, size) );
ASSERT_NO_THROW( m_testClassVar = TargetProcess::getCurrent()->getManagedVar(address) );
}
......
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