mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-19 19:13:22 +08:00
[~] 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:
parent
0320bfce38
commit
c6a92278cf
@ -132,7 +132,8 @@ BOOST_PYTHON_MODULE( pykd )
|
||||
python::def( "diaLoadPdb", &pyDia::GlobalScope::loadPdb,
|
||||
"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,
|
||||
"Retrieves the children of the symbol" )
|
||||
.def( "find", &pyDia::Symbol::findChildren,
|
||||
@ -177,7 +178,8 @@ BOOST_PYTHON_MODULE( pykd )
|
||||
.def("__len__", &pyDia::Symbol::getChildCount )
|
||||
.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,
|
||||
"Find symbol by RVA. Return tuple: (DiaSymbol, offset)")
|
||||
.def("symbolById", &pyDia::GlobalScope::getSymbolById,
|
||||
|
@ -59,7 +59,7 @@ void Exception::exceptionTranslate( const Exception &e )
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::list< Symbol > Symbol::findChildrenImpl(
|
||||
std::list< SymbolPtr > Symbol::findChildrenImpl(
|
||||
ULONG symTag,
|
||||
const std::string &name,
|
||||
DWORD nameCmpFlags
|
||||
@ -75,12 +75,12 @@ std::list< Symbol > Symbol::findChildrenImpl(
|
||||
if (S_OK != hres)
|
||||
throw Exception("Call IDiaSymbol::findChildren", hres);
|
||||
|
||||
std::list< Symbol > childList;
|
||||
std::list< SymbolPtr > childList;
|
||||
|
||||
DiaSymbolPtr child;
|
||||
ULONG celt;
|
||||
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;
|
||||
}
|
||||
@ -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;
|
||||
HRESULT hres =
|
||||
@ -276,7 +276,7 @@ Symbol Symbol::getChildByName(const std::string &_name)
|
||||
if (S_OK != 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;
|
||||
HRESULT hres =
|
||||
@ -331,7 +331,7 @@ Symbol Symbol::getChildByIndex(ULONG _index)
|
||||
if (S_OK != 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;
|
||||
|
||||
@ -379,12 +379,12 @@ GlobalScope GlobalScope::loadPdb(const std::string &filePath)
|
||||
if ( S_OK != 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 symTag,
|
||||
__out LONG &displacement
|
||||
@ -402,12 +402,12 @@ Symbol GlobalScope::findByRvaImpl(
|
||||
if (!child)
|
||||
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;
|
||||
HRESULT hres = m_session->symbolById(symId, &_symbol);
|
||||
@ -416,7 +416,7 @@ Symbol GlobalScope::getSymbolById(ULONG symId)
|
||||
if (!_symbol)
|
||||
throw Exception("Call IDiaSession::findSymbolByRVAEx", E_UNEXPECTED);
|
||||
|
||||
return Symbol( _symbol, m_machineType );
|
||||
return SymbolPtr( new Symbol(_symbol, m_machineType) );
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -1,6 +1,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <boost\smart_ptr\scoped_ptr.hpp>
|
||||
|
||||
#include <cvconst.h>
|
||||
|
||||
#include "utils.h"
|
||||
@ -51,6 +53,9 @@ private:
|
||||
HRESULT m_hres;
|
||||
};
|
||||
|
||||
class Symbol;
|
||||
typedef boost::shared_ptr< Symbol > SymbolPtr;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Symbol
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -60,8 +65,19 @@ public:
|
||||
{
|
||||
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,
|
||||
const std::string &name,
|
||||
DWORD nameCmpFlags
|
||||
@ -87,9 +103,9 @@ public:
|
||||
|
||||
std::string getName();
|
||||
|
||||
Symbol getType();
|
||||
SymbolPtr getType();
|
||||
|
||||
Symbol getIndexType();
|
||||
SymbolPtr getIndexType();
|
||||
|
||||
ULONG getSymTag();
|
||||
|
||||
@ -120,9 +136,9 @@ public:
|
||||
return m_machineType;
|
||||
}
|
||||
|
||||
Symbol getChildByName(const std::string &_name);
|
||||
SymbolPtr getChildByName(const std::string &_name);
|
||||
ULONG getChildCount();
|
||||
Symbol getChildByIndex(ULONG _index);
|
||||
SymbolPtr getChildByIndex(ULONG _index);
|
||||
|
||||
std::string print();
|
||||
public:
|
||||
@ -197,22 +213,13 @@ protected:
|
||||
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;
|
||||
DWORD m_machineType;
|
||||
};
|
||||
|
||||
class GlobalScope;
|
||||
typedef boost::shared_ptr< GlobalScope > GlobalScopePtr;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Global scope: source + sessions
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -221,7 +228,7 @@ public:
|
||||
GlobalScope() {}
|
||||
|
||||
// GlobalScope factory
|
||||
static GlobalScope loadPdb(const std::string &filePath);
|
||||
static GlobalScopePtr loadPdb(const std::string &filePath);
|
||||
|
||||
// RVA -> Symbol
|
||||
python::tuple findByRva(
|
||||
@ -230,17 +237,17 @@ public:
|
||||
)
|
||||
{
|
||||
LONG displacement;
|
||||
Symbol child = findByRvaImpl(rva, symTag, displacement);
|
||||
SymbolPtr child = findByRvaImpl(rva, symTag, displacement);
|
||||
return python::make_tuple(child, displacement);
|
||||
}
|
||||
Symbol findByRvaImpl(
|
||||
SymbolPtr findByRvaImpl(
|
||||
__in ULONG rva,
|
||||
__in ULONG symTag,
|
||||
__out LONG &displacement
|
||||
);
|
||||
|
||||
// get symbol by unique index
|
||||
Symbol getSymbolById(ULONG symId);
|
||||
SymbolPtr getSymbolById(ULONG symId);
|
||||
|
||||
private:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user