[~] pyDia: return object over shared_ptr

git-svn-id: https://pykd.svn.codeplex.com/svn@70035 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\EreTIk_cp 2011-09-26 08:38:28 +00:00 committed by Mikhail I. Izmestev
parent 0320bfce38
commit c6a92278cf
3 changed files with 49 additions and 40 deletions

View File

@ -132,7 +132,8 @@ BOOST_PYTHON_MODULE( pykd )
python::def( "diaLoadPdb", &pyDia::GlobalScope::loadPdb, python::def( "diaLoadPdb", &pyDia::GlobalScope::loadPdb,
"Open pdb file for quering debug symbols. Return DiaSymbol of global scope"); "Open pdb file for quering debug symbols. Return DiaSymbol of global scope");
python::class_<pyDia::Symbol>("DiaSymbol", "class wrapper for MS DIA Symbol" ) python::class_<pyDia::Symbol, pyDia::SymbolPtr>(
"DiaSymbol", "class wrapper for MS DIA Symbol", python::no_init )
.def( "findEx", &pyDia::Symbol::findChildrenEx, .def( "findEx", &pyDia::Symbol::findChildrenEx,
"Retrieves the children of the symbol" ) "Retrieves the children of the symbol" )
.def( "find", &pyDia::Symbol::findChildren, .def( "find", &pyDia::Symbol::findChildren,
@ -177,7 +178,8 @@ BOOST_PYTHON_MODULE( pykd )
.def("__len__", &pyDia::Symbol::getChildCount ) .def("__len__", &pyDia::Symbol::getChildCount )
.def("__getitem__", &pyDia::Symbol::getChildByIndex); .def("__getitem__", &pyDia::Symbol::getChildByIndex);
python::class_<pyDia::GlobalScope, python::bases<pyDia::Symbol> >("DiaScope", "class wrapper for MS DIA Symbol" ) python::class_<pyDia::GlobalScope, pyDia::GlobalScopePtr, python::bases<pyDia::Symbol> >(
"DiaScope", "class wrapper for MS DIA Symbol", python::no_init )
.def("findByRva", &pyDia::GlobalScope::findByRva, .def("findByRva", &pyDia::GlobalScope::findByRva,
"Find symbol by RVA. Return tuple: (DiaSymbol, offset)") "Find symbol by RVA. Return tuple: (DiaSymbol, offset)")
.def("symbolById", &pyDia::GlobalScope::getSymbolById, .def("symbolById", &pyDia::GlobalScope::getSymbolById,

View File

@ -59,7 +59,7 @@ void Exception::exceptionTranslate( const Exception &e )
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
std::list< Symbol > Symbol::findChildrenImpl( std::list< SymbolPtr > Symbol::findChildrenImpl(
ULONG symTag, ULONG symTag,
const std::string &name, const std::string &name,
DWORD nameCmpFlags DWORD nameCmpFlags
@ -75,12 +75,12 @@ std::list< Symbol > Symbol::findChildrenImpl(
if (S_OK != hres) if (S_OK != hres)
throw Exception("Call IDiaSymbol::findChildren", hres); throw Exception("Call IDiaSymbol::findChildren", hres);
std::list< Symbol > childList; std::list< SymbolPtr > childList;
DiaSymbolPtr child; DiaSymbolPtr child;
ULONG celt; ULONG celt;
while ( SUCCEEDED(symbols->Next(1, &child, &celt)) && (celt == 1) ) while ( SUCCEEDED(symbols->Next(1, &child, &celt)) && (celt == 1) )
childList.push_back( Symbol(child, m_machineType) ); childList.push_back( SymbolPtr( new Symbol(child, m_machineType) ) );
return childList; return childList;
} }
@ -102,16 +102,16 @@ std::string Symbol::getName()
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
Symbol Symbol::getType() SymbolPtr Symbol::getType()
{ {
return Symbol( callSymbol(get_type), m_machineType ); return SymbolPtr( new Symbol(callSymbol(get_type), m_machineType) );
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
Symbol Symbol::getIndexType() SymbolPtr Symbol::getIndexType()
{ {
return Symbol( callSymbol(get_arrayIndexType), m_machineType ); return SymbolPtr( new Symbol(callSymbol(get_arrayIndexType), m_machineType) );
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -248,7 +248,7 @@ ULONG Symbol::getRegisterId()
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
Symbol Symbol::getChildByName(const std::string &_name) SymbolPtr Symbol::getChildByName(const std::string &_name)
{ {
DiaEnumSymbolsPtr symbols; DiaEnumSymbolsPtr symbols;
HRESULT hres = HRESULT hres =
@ -276,7 +276,7 @@ Symbol Symbol::getChildByName(const std::string &_name)
if (S_OK != hres) if (S_OK != hres)
throw Exception("Call IDiaEnumSymbols::Item", hres); throw Exception("Call IDiaEnumSymbols::Item", hres);
return Symbol(child, m_machineType); return SymbolPtr( new Symbol(child, m_machineType) );
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -303,7 +303,7 @@ ULONG Symbol::getChildCount()
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
Symbol Symbol::getChildByIndex(ULONG _index) SymbolPtr Symbol::getChildByIndex(ULONG _index)
{ {
DiaEnumSymbolsPtr symbols; DiaEnumSymbolsPtr symbols;
HRESULT hres = HRESULT hres =
@ -331,7 +331,7 @@ Symbol Symbol::getChildByIndex(ULONG _index)
if (S_OK != hres) if (S_OK != hres)
throw Exception("Call IDiaEnumSymbols::Item", hres); throw Exception("Call IDiaEnumSymbols::Item", hres);
return Symbol(child, m_machineType); return SymbolPtr( new Symbol(child, m_machineType) );
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -356,7 +356,7 @@ GlobalScope::GlobalScope(
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
GlobalScope GlobalScope::loadPdb(const std::string &filePath) GlobalScopePtr GlobalScope::loadPdb(const std::string &filePath)
{ {
DiaDataSourcePtr _scope; DiaDataSourcePtr _scope;
@ -379,12 +379,12 @@ GlobalScope GlobalScope::loadPdb(const std::string &filePath)
if ( S_OK != hres ) if ( S_OK != hres )
throw Exception("Call IDiaSymbol::get_globalScope", hres); throw Exception("Call IDiaSymbol::get_globalScope", hres);
return GlobalScope(_scope, _session, _globalScope); return GlobalScopePtr( new GlobalScope(_scope, _session, _globalScope) );
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
Symbol GlobalScope::findByRvaImpl( SymbolPtr GlobalScope::findByRvaImpl(
__in ULONG rva, __in ULONG rva,
__in ULONG symTag, __in ULONG symTag,
__out LONG &displacement __out LONG &displacement
@ -402,12 +402,12 @@ Symbol GlobalScope::findByRvaImpl(
if (!child) if (!child)
throw Exception("Call IDiaSession::findSymbolByRVAEx", E_UNEXPECTED); throw Exception("Call IDiaSession::findSymbolByRVAEx", E_UNEXPECTED);
return Symbol( child, m_machineType ); return SymbolPtr( new Symbol(child, m_machineType) );
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
Symbol GlobalScope::getSymbolById(ULONG symId) SymbolPtr GlobalScope::getSymbolById(ULONG symId)
{ {
DiaSymbolPtr _symbol; DiaSymbolPtr _symbol;
HRESULT hres = m_session->symbolById(symId, &_symbol); HRESULT hres = m_session->symbolById(symId, &_symbol);
@ -416,7 +416,7 @@ Symbol GlobalScope::getSymbolById(ULONG symId)
if (!_symbol) if (!_symbol)
throw Exception("Call IDiaSession::findSymbolByRVAEx", E_UNEXPECTED); throw Exception("Call IDiaSession::findSymbolByRVAEx", E_UNEXPECTED);
return Symbol( _symbol, m_machineType ); return SymbolPtr( new Symbol(_symbol, m_machineType) );
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@ -1,6 +1,8 @@
#pragma once #pragma once
#include <boost\smart_ptr\scoped_ptr.hpp>
#include <cvconst.h> #include <cvconst.h>
#include "utils.h" #include "utils.h"
@ -51,6 +53,9 @@ private:
HRESULT m_hres; HRESULT m_hres;
}; };
class Symbol;
typedef boost::shared_ptr< Symbol > SymbolPtr;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Symbol // Symbol
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -60,8 +65,19 @@ public:
{ {
throw Exception("DiaSymbol must be created over factory from DiaScope::..."); throw Exception("DiaSymbol must be created over factory from DiaScope::...");
} }
Symbol(__inout DiaSymbolPtr &_symbol, DWORD machineType)
: m_machineType(machineType)
{
m_symbol = _symbol.Detach();
}
Symbol(__in IDiaSymbol *_symbol, DWORD machineType)
: m_machineType(machineType)
{
m_symbol = _symbol;
}
std::list< Symbol > findChildrenImpl(
std::list< SymbolPtr > findChildrenImpl(
ULONG symTag, ULONG symTag,
const std::string &name, const std::string &name,
DWORD nameCmpFlags DWORD nameCmpFlags
@ -87,9 +103,9 @@ public:
std::string getName(); std::string getName();
Symbol getType(); SymbolPtr getType();
Symbol getIndexType(); SymbolPtr getIndexType();
ULONG getSymTag(); ULONG getSymTag();
@ -120,9 +136,9 @@ public:
return m_machineType; return m_machineType;
} }
Symbol getChildByName(const std::string &_name); SymbolPtr getChildByName(const std::string &_name);
ULONG getChildCount(); ULONG getChildCount();
Symbol getChildByIndex(ULONG _index); SymbolPtr getChildByIndex(ULONG _index);
std::string print(); std::string print();
public: public:
@ -197,22 +213,13 @@ protected:
return retValue; return retValue;
} }
Symbol(__inout DiaSymbolPtr &_symbol, DWORD machineType)
: m_machineType(machineType)
{
m_symbol = _symbol.Detach();
}
Symbol(__in IDiaSymbol *_symbol, DWORD machineType)
: m_machineType(machineType)
{
m_symbol = _symbol;
}
DiaSymbolPtr m_symbol; DiaSymbolPtr m_symbol;
DWORD m_machineType; DWORD m_machineType;
}; };
class GlobalScope;
typedef boost::shared_ptr< GlobalScope > GlobalScopePtr;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Global scope: source + sessions // Global scope: source + sessions
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -221,7 +228,7 @@ public:
GlobalScope() {} GlobalScope() {}
// GlobalScope factory // GlobalScope factory
static GlobalScope loadPdb(const std::string &filePath); static GlobalScopePtr loadPdb(const std::string &filePath);
// RVA -> Symbol // RVA -> Symbol
python::tuple findByRva( python::tuple findByRva(
@ -230,17 +237,17 @@ public:
) )
{ {
LONG displacement; LONG displacement;
Symbol child = findByRvaImpl(rva, symTag, displacement); SymbolPtr child = findByRvaImpl(rva, symTag, displacement);
return python::make_tuple(child, displacement); return python::make_tuple(child, displacement);
} }
Symbol findByRvaImpl( SymbolPtr findByRvaImpl(
__in ULONG rva, __in ULONG rva,
__in ULONG symTag, __in ULONG symTag,
__out LONG &displacement __out LONG &displacement
); );
// get symbol by unique index // get symbol by unique index
Symbol getSymbolById(ULONG symId); SymbolPtr getSymbolById(ULONG symId);
private: private: