diff --git a/pykd/dbgclient.cpp b/pykd/dbgclient.cpp index 0d4e3c7..4a6d0c8 100644 --- a/pykd/dbgclient.cpp +++ b/pykd/dbgclient.cpp @@ -16,7 +16,11 @@ DebugClient::DebugClient() hres = m_client->QueryInterface( __uuidof(IDebugControl4), (void**)&m_control ); if ( FAILED( hres ) ) - throw DbgException("QueryInterface IDebugControl4 failed"); + throw DbgException("QueryInterface IDebugControl4 failed"); + + hres = m_client->QueryInterface( __uuidof(IDebugSymbols3), (void**)&m_symbols ); + if ( FAILED( hres ) ) + throw DbgException("QueryInterface IDebugSymbols3 failed"); } /////////////////////////////////////////////////////////////////////////////////// diff --git a/pykd/dbgclient.h b/pykd/dbgclient.h index e684d7e..04e6222 100644 --- a/pykd/dbgclient.h +++ b/pykd/dbgclient.h @@ -5,6 +5,7 @@ #include #include "dbgexcept.h" +#include "module.h" ///////////////////////////////////////////////////////////////////////////////// @@ -28,10 +29,16 @@ public: void attachKernel( const std::wstring ¶m ); + Module loadModule( const std::string &moduleName ) { + return Module( m_client, moduleName ); + } + + private: CComPtr m_client; CComPtr m_control; + CComPtr m_symbols; }; ///////////////////////////////////////////////////////////////////////////////// diff --git a/pykd/dbgext.cpp b/pykd/dbgext.cpp index ab8b668..519342d 100644 --- a/pykd/dbgext.cpp +++ b/pykd/dbgext.cpp @@ -82,10 +82,19 @@ BOOST_PYTHON_MODULE( pykd ) .def( "loadDump", &pykd::DebugClient::loadDump, "Load crash dump" ) .def( "startProcess", &pykd::DebugClient::startProcess, "Start process for debugging" ) .def( "attachProcess", &pykd::DebugClient::attachProcess, "Attach debugger to a exsisting process" ) - .def( "attachKernel", &pykd::DebugClient::attachKernel, "Attach debugger to a target's kernel" ); + .def( "attachKernel", &pykd::DebugClient::attachKernel, "Attach debugger to a target's kernel" ) + .def( "loadModule", &pykd::DebugClient::loadModule, "Create instance of Module class" ); python::class_("module", "Class representing executable module", python::no_init ) - .def( python::init( "constructor" ) ); + .def("begin", &pykd::Module::getBase, + "Return start address of the module" ) + .def("end", &pykd::Module::getEnd, + "Return end address of the module" ) + .def("size", &pykd::Module::getSize, + "Return size of the module" ) + .def("name", &pykd::Module::getName, + "Return name of the module" ); + python::def( "diaOpenPdb", &pyDia::GlobalScope::openPdb, "Open pdb file for quering debug symbols. Return DiaSymbol of global scope"); diff --git a/pykd/dbgobj.h b/pykd/dbgobj.h new file mode 100644 index 0000000..6875ca1 --- /dev/null +++ b/pykd/dbgobj.h @@ -0,0 +1,41 @@ +#pragma once + +#include +#include "dbgexcept.h" + +namespace pykd { + +/////////////////////////////////////////////////////////////////////////////////// + +class DbgObject { + +protected: + + DbgObject( IDebugClient5 *client ) { + + HRESULT hres; + hres = client->QueryInterface( __uuidof(IDebugClient5), (void **)&m_client ); + if ( FAILED( hres ) ) + throw DbgException("DebugCreate failed"); + + hres = client->QueryInterface( __uuidof(IDebugControl4), (void**)&m_control ); + if ( FAILED( hres ) ) + throw DbgException("QueryInterface IDebugControl4 failed"); + + hres = client->QueryInterface( __uuidof(IDebugSymbols3), (void**)&m_symbols ); + if ( FAILED( hres ) ) + throw DbgException("QueryInterface IDebugSymbols3 failed"); + } + + virtual ~DbgObject() {}; + + CComPtr m_client; + CComPtr m_control; + CComPtr m_symbols; +}; + + + +/////////////////////////////////////////////////////////////////////////////////// + +}; // end of namespace pykd \ No newline at end of file diff --git a/pykd/module.cpp b/pykd/module.cpp index a7f619f..4af45db 100644 --- a/pykd/module.cpp +++ b/pykd/module.cpp @@ -1,5 +1,39 @@ #include "stdafx.h" +#include "module.h" + +using namespace pykd; + +/////////////////////////////////////////////////////////////////////////////////// + +Module::Module( IDebugClient5 *client, const std::string& moduleName ) : DbgObject( client ) +{ + HRESULT hres; + + m_name = moduleName; + + hres = m_symbols->GetModuleByModuleName( moduleName.c_str(), 0, NULL, &m_base ); + if ( FAILED( hres ) ) + throw DbgException( "IDebugSymbol::GetModuleByModuleName failed" ); + + DEBUG_MODULE_PARAMETERS moduleParam = { 0 }; + hres = m_symbols->GetModuleParameters( 1, &m_base, 0, &moduleParam ); + if ( FAILED( hres ) ) + throw DbgException( "IDebugSymbol::GetModuleParameters failed" ); + + m_size = moduleParam.Size; +} + +/////////////////////////////////////////////////////////////////////////////////// + + + + + + + + + //#include // //#include "dbgext.h" diff --git a/pykd/module.h b/pykd/module.h index b7ccb6a..2df26f5 100644 --- a/pykd/module.h +++ b/pykd/module.h @@ -1,15 +1,41 @@ #pragma once +#include + +#include "dbgobj.h" + namespace pykd { /////////////////////////////////////////////////////////////////////////////////// -class Module { +class Module : private DbgObject { public: + + Module( IDebugClient5 *client, const std::string& moduleName ); + + std::string getName() { + return m_name; + } + + ULONG64 getBase() { + return m_base; + } + + ULONG64 getEnd() { + return m_base + m_size; + } + + ULONG getSize() { + return m_size; + } + +private: + + std::string m_name; + ULONG64 m_base; + ULONG m_size; - Module( const std::string &moduleName ) - {} }; /////////////////////////////////////////////////////////////////////////////////// @@ -17,6 +43,15 @@ public: }; + + + + + + + + + //#include //#include // diff --git a/pykd/pykd_2008.vcproj b/pykd/pykd_2008.vcproj index a5dc5b2..5f27921 100644 --- a/pykd/pykd_2008.vcproj +++ b/pykd/pykd_2008.vcproj @@ -1,7 +1,7 @@ + + diff --git a/pykd_2008.sln b/pykd_01_2008.sln similarity index 100% rename from pykd_2008.sln rename to pykd_01_2008.sln diff --git a/test/scripts/moduletest.py b/test/scripts/moduletest.py new file mode 100644 index 0000000..96e72e4 --- /dev/null +++ b/test/scripts/moduletest.py @@ -0,0 +1,24 @@ +# +# +# + +import unittest +import target +import pykd + +class ModuleTest( unittest.TestCase ): + + def testCtor( self ): + self.assertRaises( RuntimeError, pykd.module ) + + def testName( self ): + self.assertEqual( target.moduleName, target.module.name() ) + + def testSize( self ): + self.assertNotEqual( 0, target.module.size() ) + + def testBegin( self ): + self.assertNotEqual( 0, target.module.begin() ) + + def testEnd( self ): + self.assertEqual( target.module.size(), target.module.end() - target.module.begin() ) diff --git a/test/scripts/pykdtest.py b/test/scripts/pykdtest.py index 63d861a..393a407 100644 --- a/test/scripts/pykdtest.py +++ b/test/scripts/pykdtest.py @@ -16,8 +16,6 @@ import typeinfo import regtest import moduletest -print dir(pykd) - def getTestSuite( singleName = "" ): if singleName == "": return unittest.TestSuite( @@ -38,11 +36,11 @@ if __name__ == "__main__": print "\nTest module: %s" % targetAppPath dbg = pykd.dbgClient() - + dbg.startProcess( targetAppPath ) # pykd.go() -# target.module = pykd.loadModule( target.moduleName ) + target.module = dbg.loadModule( target.moduleName ) suite = getTestSuite()