diff --git a/pykd/dbgext.cpp b/pykd/dbgext.cpp index c53a9dd..36fb439 100644 --- a/pykd/dbgext.cpp +++ b/pykd/dbgext.cpp @@ -724,11 +724,11 @@ BOOST_PYTHON_MODULE( pykd ) "Retrieves the type of the target CPU: IMAGE_FILE_MACHINE_XXX") .def( "__str__", &pyDia::Symbol::print) .def("__getitem__", &pyDia::Symbol::getChildByName) - .def("__len__", (ULONG (pyDia::Symbol::*)())&pyDia::Symbol::getChildCount ) - .def("__getitem__", (pyDia::SymbolPtr(pyDia::Symbol::*)(ULONG) )&pyDia::Symbol::getChildByIndex) + .def("__len__", &pyDia::Symbol::getChildCount ) + .def("__getitem__", &pyDia::Symbol::getChildByIndex ) .def("__eq__", &pyDia::Symbol::eq) .def("__hash__", &pyDia::Symbol::getIndexId); - + python::class_ >( "DiaScope", "class wrapper for MS DIA Symbol", python::no_init ) .def("findByRva", &pyDia::GlobalScope::findByRva, diff --git a/pykd/diawrapper.cpp b/pykd/diawrapper.cpp index 1f64dd4..0e2da88 100644 --- a/pykd/diawrapper.cpp +++ b/pykd/diawrapper.cpp @@ -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(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(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() { return printImpl(m_symbol, m_machineType); diff --git a/pykd/diawrapper.h b/pykd/diawrapper.h index 9dbcf47..977fc0a 100644 --- a/pykd/diawrapper.h +++ b/pykd/diawrapper.h @@ -134,10 +134,20 @@ public: SymbolPtr getChildByName(const std::string &_name); - ULONG getChildCount( ULONG symTag = SymTagNull ); + template + ULONG getChildCount(); - SymbolPtr getChildByIndex(ULONG _index, ULONG symTag = SymTagNull ); + ULONG getChildCount() { + return getChildCount(); + } + template + SymbolPtr getChildByIndex(ULONG _index ); + + SymbolPtr getChildByIndex(ULONG _index ) { + return getChildByIndex( _index ); + } + bool isConstant(); std::string print(); @@ -276,4 +286,61 @@ private: //////////////////////////////////////////////////////////////////////////////// +template +ULONG Symbol::getChildCount() +{ + DiaEnumSymbolsPtr symbols; + HRESULT hres = + m_symbol->findChildren( + static_cast(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 +SymbolPtr Symbol::getChildByIndex(ULONG _index ) +{ + DiaEnumSymbolsPtr symbols; + HRESULT hres = + m_symbol->findChildren( + static_cast(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) ); +} + +//////////////////////////////////////////////////////////////////////////////// + }; diff --git a/pykd/typeinfo.cpp b/pykd/typeinfo.cpp index dc07b9d..0bcb096 100644 --- a/pykd/typeinfo.cpp +++ b/pykd/typeinfo.cpp @@ -463,10 +463,10 @@ TypeInfoPtr UdtTypeInfo::getField( const std::string &fieldName ) TypeInfoPtr UdtTypeInfo::getFieldByIndex( ULONG index ) { - if ( index >= m_dia->getChildCount(SymTagData) ) + if ( index >= m_dia->getChildCount() ) throw TypeException( m_dia->getName(), ": field not found" ); - pyDia::SymbolPtr field = m_dia->getChildByIndex(index, SymTagData); + pyDia::SymbolPtr field = m_dia->getChildByIndex(index); if ( !field ) throw TypeException( m_dia->getName(), ": field not found" ); @@ -480,10 +480,10 @@ TypeInfoPtr UdtTypeInfo::getFieldByIndex( ULONG index ) std::string UdtTypeInfo::getFieldNameByIndex( ULONG index ) { - if ( index >= m_dia->getChildCount( SymTagData ) ) + if ( index >= m_dia->getChildCount() ) throw TypeException( m_dia->getName(), ": field not found" ); - pyDia::SymbolPtr field = m_dia->getChildByIndex(index, SymTagData); + pyDia::SymbolPtr field = m_dia->getChildByIndex(index); if ( !field ) throw TypeException( m_dia->getName(), ": field not found" ); @@ -495,7 +495,7 @@ std::string UdtTypeInfo::getFieldNameByIndex( ULONG index ) ULONG UdtTypeInfo::getFieldCount() { - return m_dia->getChildCount( SymTagData ); + return m_dia->getChildCount(); } /////////////////////////////////////////////////////////////////////////////////////