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

added heap enum class

git-svn-id: https://kdlibcpp.svn.codeplex.com/svn@91253 9b283d60-5439-405e-af05-b73fd8c4d996
parent a786efcd
......@@ -2,6 +2,8 @@
#include <boost/smart_ptr.hpp>
#include "kdlib/dbgtypedef.h"
namespace kdlib {
///////////////////////////////////////////////////////////////////////////////
......@@ -9,6 +11,9 @@ namespace kdlib {
class TargetHeap;
typedef boost::shared_ptr<TargetHeap> TargetHeapPtr;
class TargetHeapEnum;
typedef boost::shared_ptr<TargetHeapEnum> TargetHeapEnumPtr;
///////////////////////////////////////////////////////////////////////////////
class TargetHeap
......@@ -16,6 +21,15 @@ class TargetHeap
public:
virtual size_t getCount(const std::wstring& typeName=L"", size_t minSize = 0, size_t maxSize = -1) const = 0;
virtual TargetHeapEnumPtr getEnum(const std::wstring& typeName=L"", size_t minSize = 0, size_t maxSize = -1) = 0;
};
class TargetHeapEnum
{
public:
virtual bool Next(MEMOFFSET_64& addr, std::wstring& typeName, size_t& typeSize) = 0;
};
TargetHeapPtr getManagedHeap();
......
......@@ -78,10 +78,10 @@ size_t NetHeap::getCount(const std::wstring& typeName, size_t minSize, size_t
if ( !typeName.empty() && !fnmatch(typeName, typeObj->getName() ))
continue;
if ( minSize != 0 && typeObj->getSize() < minSize )
if ( minSize != 0 && heapObj.size < minSize )
continue;
if ( maxSize != -1 && typeObj->getSize() > maxSize )
if ( maxSize != -1 && heapObj.size > maxSize )
continue;
}
......@@ -93,4 +93,63 @@ size_t NetHeap::getCount(const std::wstring& typeName, size_t minSize, size_t
///////////////////////////////////////////////////////////////////////////////
TargetHeapEnumPtr NetHeap::getEnum(const std::wstring& typeName, size_t minSize, size_t maxSize)
{
return TargetHeapEnumPtr( new NetHeapEnum(typeName, minSize, maxSize) );
}
///////////////////////////////////////////////////////////////////////////////
NetHeapEnum::NetHeapEnum(const std::wstring& typeName, size_t minSize, size_t maxSize) :
m_typeMask(typeName),
m_minSize(minSize),
m_maxSize(maxSize)
{
HRESULT hres = g_netMgr->targetProcess5()->EnumerateHeap(&m_heapEnum);
if (FAILED(hres))
throw DbgException("Failed ICorDebugProcess5::EnumerateHeap");
}
///////////////////////////////////////////////////////////////////////////////
bool NetHeapEnum::Next(MEMOFFSET_64& addr, std::wstring& typeName, size_t& size)
{
HRESULT hres;
while(true)
{
COR_HEAPOBJECT heapObj;
hres = m_heapEnum->Next(1, &heapObj, NULL);
if (FAILED(hres))
throw DbgException("Failed ICorDebugHeapEnum::Next");
if ( S_OK != hres )
return false;
TypeInfoPtr typeObj = getTypeById(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;
addr = heapObj.address;
typeName = tn;
size = heapObj.size;
return true;
}
throw DbgException("NetHeapEnum::Next undefined behaviour");
}
///////////////////////////////////////////////////////////////////////////////
}
#pragma once
#include <atlbase.h>
#include <CorDebug.h>
#include "kdlib/heap.h"
namespace kdlib {
......@@ -12,6 +15,27 @@ protected:
virtual size_t getCount(const std::wstring& typeName, size_t minSize = 0, size_t maxSize = -1) const;
virtual TargetHeapEnumPtr getEnum(const std::wstring& typeName=L"", size_t minSize = 0, size_t maxSize = -1);
};
class NetHeapEnum : public TargetHeapEnum
{
public:
NetHeapEnum(const std::wstring& typeName=L"", size_t minSize = 0, size_t maxSize = -1);
private:
virtual bool Next(MEMOFFSET_64& addr, std::wstring& typeName, size_t& size);
private:
std::wstring m_typeMask;
size_t m_minSize;
size_t m_maxSize;
CComPtr<ICorDebugHeapEnum> m_heapEnum;
};
///////////////////////////////////////////////////////////////////////////////
......
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