diff --git a/pykd/dbgext.cpp b/pykd/dbgext.cpp index a7422ad..c616d26 100644 --- a/pykd/dbgext.cpp +++ b/pykd/dbgext.cpp @@ -280,7 +280,7 @@ py( PDEBUG_CLIENT4 client, PCSTR args ) } catch(...) { - eprintln( L"unexpected error" ); + eprintln( L"unexpected error" ); } Py_EndInterpreter( localInterpreter ); @@ -308,17 +308,17 @@ pycmd( PDEBUG_CLIENT4 client, PCSTR args ) try { python::exec( - "try:\n" - " __import__('code').InteractiveConsole(__import__('__main__').__dict__).interact()\n" - "except SystemExit:\n" - " print 'Ctrl+Break'\n", + "__import__('code').InteractiveConsole(__import__('__main__').__dict__).interact()\n", WindbgGlobalSession::global(), WindbgGlobalSession::global() ); } catch(...) { - eprintln( L"unexpected error" ); + if ( !PyErr_ExceptionMatches( PyExc_SystemExit ) ) + { + eprintln( L"unexpected error" ); + } } // выход из интерпретатора происходит через исключение raise SystemExit(code) diff --git a/pykd/dia/diawrapper.cpp b/pykd/dia/diawrapper.cpp index 76c0f75..7c3aedd 100644 --- a/pykd/dia/diawrapper.cpp +++ b/pykd/dia/diawrapper.cpp @@ -206,7 +206,7 @@ SymbolPtrList DiaSymbol::findChildren( hres = m_symbol->findChildren( static_cast(symTag), NULL, - (caseSensitive ? nsCaseSensitive : nsCaseInsensitive) | nsfUndecoratedName, + (caseSensitive ? nsCaseSensitive : nsCaseInsensitive) | nsfUndecoratedName | nsfRegularExpression, &symbols); } @@ -215,7 +215,7 @@ SymbolPtrList DiaSymbol::findChildren( hres = m_symbol->findChildren( static_cast(symTag), toWStr(name), - (caseSensitive ? nsCaseSensitive : nsCaseInsensitive) | nsfUndecoratedName, + (caseSensitive ? nsCaseSensitive : nsCaseInsensitive) | nsfUndecoratedName | nsfRegularExpression, &symbols); } @@ -652,7 +652,14 @@ bool DiaSymbol::isBasicType() bool DiaSymbol::isConstant() { - return !!callSymbol(get_constType); + HRESULT hres; + BOOL retBool = FALSE; + + hres = m_symbol->get_constType( &retBool ); + if ( FAILED( hres ) ) + throw DiaException("Call IDiaSymbol::get_constType", hres, m_symbol); + + return !!retBool; } ////////////////////////////////////////////////////////////////////////////// diff --git a/pykd/module.cpp b/pykd/module.cpp index 07375e7..9f9dfcc 100644 --- a/pykd/module.cpp +++ b/pykd/module.cpp @@ -196,7 +196,7 @@ TypedVarPtr Module::containingRecordByName( ULONG64 offset, const std::string &t return containingRecordByType( offset, typeInfo, fieldName ); } -/////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// python::list Module::getTypedVarArrayByTypeName( ULONG64 offset, const std::string &typeName, ULONG number ) { @@ -281,4 +281,34 @@ void Module::prepareSymbolFile() /////////////////////////////////////////////////////////////////////////////////// +python::list Module::enumSymbols( const std::string &mask) +{ + python::list lst; + + SymbolPtrList symlst = getSymScope()->findChildren( SymTagData, mask, true ); + + for ( SymbolPtrList::iterator it = symlst.begin(); it != symlst.end(); ++it ) + { + if ( (*it)->getDataKind() == DataIsConstant ) + { + lst.append( python::make_tuple( (*it)->getName(), python::object() ) ); + } + else + { + lst.append( python::make_tuple( (*it)->getName(), (*it)->getVa() ) ); + } + } + + symlst = getSymScope()->findChildren( SymTagFunction, mask, true ); + + for ( SymbolPtrList::iterator it = symlst.begin(); it != symlst.end(); ++it ) + { + lst.append( python::make_tuple( (*it)->getName(), (*it)->getVa() ) ); + } + + return lst; +} + +/////////////////////////////////////////////////////////////////////////////////// + }; // end of namespace pykd diff --git a/pykd/module.h b/pykd/module.h index 3a9842a..18884fa 100644 --- a/pykd/module.h +++ b/pykd/module.h @@ -103,6 +103,8 @@ public: std::string getSourceFile( ULONG64 offset ); + python::list enumSymbols( const std::string &mask = "*" ); + std::string print(); private: diff --git a/pykd/pykdver.h b/pykd/pykdver.h index 0963004..3c7301e 100644 --- a/pykd/pykdver.h +++ b/pykd/pykdver.h @@ -2,7 +2,7 @@ #define PYKD_VERSION_MAJOR 0 #define PYKD_VERSION_MINOR 2 #define PYKD_VERSION_SUBVERSION 0 -#define PYKD_VERSION_BUILDNO 2 +#define PYKD_VERSION_BUILDNO 3 #define __VER_STR2__(x) #x diff --git a/pykd/pymod.cpp b/pykd/pymod.cpp index d14e685..cfa2640 100644 --- a/pykd/pymod.cpp +++ b/pykd/pymod.cpp @@ -64,6 +64,8 @@ BOOST_PYTHON_FUNCTION_OVERLOADS( CustomStruct_create, CustomStruct::create, 1, 2 BOOST_PYTHON_FUNCTION_OVERLOADS( findSymbol_, TypeInfo::findSymbol, 1, 2 ); +BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( Module_enumSymbols, Module::enumSymbols, 0, 1 ); + BOOST_PYTHON_MODULE( pykd ) { python::scope().attr("version") = pykdVersion; @@ -359,6 +361,8 @@ BOOST_PYTHON_MODULE( pykd ) .def("containingRecord", &Module::containingRecordByName, "Return instance of the typedVar class. It's value are loaded from the target memory." "The start address is calculated by the same method as the standard macro CONTAINING_RECORD does" ) + .def("enumSymbols", &Module::enumSymbols, Module_enumSymbols( python::args("mask"), + "Return list of tuple ( symbolname, offset )" ) ) .def("checksum",&Module::getCheckSum, "Return a image file checksum: IMAGE_OPTIONAL_HEADER.CheckSum" ) .def("timestamp",&Module::getTimeDataStamp, diff --git a/test/scripts/moduletest.py b/test/scripts/moduletest.py index cd65e71..47b4347 100644 --- a/test/scripts/moduletest.py +++ b/test/scripts/moduletest.py @@ -52,6 +52,7 @@ class ModuleTest( unittest.TestCase ): def testFindSymbol( self ): self.assertEqual( "FuncWithName0", target.module.findSymbol( target.module.offset("FuncWithName0") ) ) self.assertEqual( "_FuncWithName2", target.module.findSymbol( target.module.offset("_FuncWithName2") ) ) + # self.assertEqual( "", typed) def testType( self ): @@ -67,5 +68,13 @@ class ModuleTest( unittest.TestCase ): self.assertEqual( 2, displacement ) fileName, lineNo, displacement = pykd.getSourceLine() self.assertEqual( 624, lineNo ) - + + def testEnumSymbols( self ): + lst = target.module.enumSymbols("hello*Str") + self.assertEqual( 2, len(lst) ) + lst = target.module.enumSymbols( "g_const*Value") + self.assertEqual( 2, len(lst) ) + lst = target.module.enumSymbols( "*FuncWithName*") + self.assertEqual( 3, len(lst) ) + self.assertNotEqual( 0, len(target.module.enumSymbols( "*virtFunc*") ) )