[0.1.x] fixed : typedVar __str__ converter - another once again ))

git-svn-id: https://pykd.svn.codeplex.com/svn@74865 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\kernelnet_cp 2012-03-12 06:14:11 +00:00 committed by Mikhail I. Izmestev
parent 2237694a8b
commit 0fba06acca
4 changed files with 77 additions and 65 deletions

View File

@ -724,11 +724,11 @@ BOOST_PYTHON_MODULE( pykd )
"Retrieves the type of the target CPU: IMAGE_FILE_MACHINE_XXX") "Retrieves the type of the target CPU: IMAGE_FILE_MACHINE_XXX")
.def( "__str__", &pyDia::Symbol::print) .def( "__str__", &pyDia::Symbol::print)
.def("__getitem__", &pyDia::Symbol::getChildByName) .def("__getitem__", &pyDia::Symbol::getChildByName)
.def("__len__", (ULONG (pyDia::Symbol::*)())&pyDia::Symbol::getChildCount ) .def("__len__", &pyDia::Symbol::getChildCount )
.def("__getitem__", (pyDia::SymbolPtr(pyDia::Symbol::*)(ULONG) )&pyDia::Symbol::getChildByIndex) .def("__getitem__", &pyDia::Symbol::getChildByIndex )
.def("__eq__", &pyDia::Symbol::eq) .def("__eq__", &pyDia::Symbol::eq)
.def("__hash__", &pyDia::Symbol::getIndexId); .def("__hash__", &pyDia::Symbol::getIndexId);
python::class_<pyDia::GlobalScope, pyDia::GlobalScopePtr, python::bases<pyDia::Symbol> >( python::class_<pyDia::GlobalScope, pyDia::GlobalScopePtr, python::bases<pyDia::Symbol> >(
"DiaScope", "class wrapper for MS DIA Symbol", python::no_init ) "DiaScope", "class wrapper for MS DIA Symbol", python::no_init )
.def("findByRva", &pyDia::GlobalScope::findByRva, .def("findByRva", &pyDia::GlobalScope::findByRva,

View File

@ -316,61 +316,6 @@ SymbolPtr Symbol::getChildByName(const std::string &_name)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
ULONG Symbol::getChildCount( ULONG symTag )
{
DiaEnumSymbolsPtr symbols;
HRESULT hres =
m_symbol->findChildren(
static_cast<enum SymTagEnum>(symTag),
NULL,
nsCaseSensitive,
&symbols);
if (S_OK != hres)
throw Exception("Call IDiaSymbol::findChildren", hres);
LONG count;
hres = symbols->get_Count(&count);
if (S_OK != hres)
throw Exception("Call IDiaEnumSymbols::get_Count", hres);
return count;
}
////////////////////////////////////////////////////////////////////////////////
SymbolPtr Symbol::getChildByIndex(ULONG _index, ULONG symTag )
{
DiaEnumSymbolsPtr symbols;
HRESULT hres =
m_symbol->findChildren(
static_cast<enum SymTagEnum>(symTag),
NULL,
nsCaseSensitive,
&symbols);
if (S_OK != hres)
throw Exception("Call IDiaSymbol::findChildren", hres);
LONG count;
hres = symbols->get_Count(&count);
if (S_OK != hres)
throw Exception("Call IDiaEnumSymbols::get_Count", hres);
if (LONG(_index) >= count)
{
PyErr_SetString(PyExc_IndexError, "Index out of range");
boost::python::throw_error_already_set();
}
DiaSymbolPtr child;
hres = symbols->Item(_index, &child);
if (S_OK != hres)
throw Exception("Call IDiaEnumSymbols::Item", hres);
return SymbolPtr( new Symbol(child, m_machineType) );
}
////////////////////////////////////////////////////////////////////////////////
std::string Symbol::print() std::string Symbol::print()
{ {
return printImpl(m_symbol, m_machineType); return printImpl(m_symbol, m_machineType);

View File

@ -134,10 +134,20 @@ public:
SymbolPtr getChildByName(const std::string &_name); SymbolPtr getChildByName(const std::string &_name);
ULONG getChildCount( ULONG symTag = SymTagNull ); template<ULONG symTag>
ULONG getChildCount();
SymbolPtr getChildByIndex(ULONG _index, ULONG symTag = SymTagNull ); ULONG getChildCount() {
return getChildCount<SymTagNull>();
}
template<ULONG symTag>
SymbolPtr getChildByIndex(ULONG _index );
SymbolPtr getChildByIndex(ULONG _index ) {
return getChildByIndex<SymTagNull>( _index );
}
bool isConstant(); bool isConstant();
std::string print(); std::string print();
@ -276,4 +286,61 @@ private:
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
template<ULONG symTag>
ULONG Symbol::getChildCount()
{
DiaEnumSymbolsPtr symbols;
HRESULT hres =
m_symbol->findChildren(
static_cast<enum SymTagEnum>(symTag),
NULL,
nsCaseSensitive,
&symbols);
if (S_OK != hres)
throw Exception("Call IDiaSymbol::findChildren", hres);
LONG count;
hres = symbols->get_Count(&count);
if (S_OK != hres)
throw Exception("Call IDiaEnumSymbols::get_Count", hres);
return count;
}
////////////////////////////////////////////////////////////////////////////////
template<ULONG symTag>
SymbolPtr Symbol::getChildByIndex(ULONG _index )
{
DiaEnumSymbolsPtr symbols;
HRESULT hres =
m_symbol->findChildren(
static_cast<enum SymTagEnum>(symTag),
NULL,
nsCaseSensitive,
&symbols);
if (S_OK != hres)
throw Exception("Call IDiaSymbol::findChildren", hres);
LONG count;
hres = symbols->get_Count(&count);
if (S_OK != hres)
throw Exception("Call IDiaEnumSymbols::get_Count", hres);
if (LONG(_index) >= count)
{
PyErr_SetString(PyExc_IndexError, "Index out of range");
boost::python::throw_error_already_set();
}
DiaSymbolPtr child;
hres = symbols->Item(_index, &child);
if (S_OK != hres)
throw Exception("Call IDiaEnumSymbols::Item", hres);
return SymbolPtr( new Symbol(child, m_machineType) );
}
////////////////////////////////////////////////////////////////////////////////
}; };

View File

@ -463,10 +463,10 @@ TypeInfoPtr UdtTypeInfo::getField( const std::string &fieldName )
TypeInfoPtr UdtTypeInfo::getFieldByIndex( ULONG index ) TypeInfoPtr UdtTypeInfo::getFieldByIndex( ULONG index )
{ {
if ( index >= m_dia->getChildCount(SymTagData) ) if ( index >= m_dia->getChildCount<SymTagData>() )
throw TypeException( m_dia->getName(), ": field not found" ); throw TypeException( m_dia->getName(), ": field not found" );
pyDia::SymbolPtr field = m_dia->getChildByIndex(index, SymTagData); pyDia::SymbolPtr field = m_dia->getChildByIndex<SymTagData>(index);
if ( !field ) if ( !field )
throw TypeException( m_dia->getName(), ": field not found" ); throw TypeException( m_dia->getName(), ": field not found" );
@ -480,10 +480,10 @@ TypeInfoPtr UdtTypeInfo::getFieldByIndex( ULONG index )
std::string UdtTypeInfo::getFieldNameByIndex( ULONG index ) std::string UdtTypeInfo::getFieldNameByIndex( ULONG index )
{ {
if ( index >= m_dia->getChildCount( SymTagData ) ) if ( index >= m_dia->getChildCount<SymTagData>() )
throw TypeException( m_dia->getName(), ": field not found" ); throw TypeException( m_dia->getName(), ": field not found" );
pyDia::SymbolPtr field = m_dia->getChildByIndex(index, SymTagData); pyDia::SymbolPtr field = m_dia->getChildByIndex<SymTagData>(index);
if ( !field ) if ( !field )
throw TypeException( m_dia->getName(), ": field not found" ); throw TypeException( m_dia->getName(), ": field not found" );
@ -495,7 +495,7 @@ std::string UdtTypeInfo::getFieldNameByIndex( ULONG index )
ULONG UdtTypeInfo::getFieldCount() ULONG UdtTypeInfo::getFieldCount()
{ {
return m_dia->getChildCount( SymTagData ); return m_dia->getChildCount<SymTagData>();
} }
///////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////