[0.1.x] added : ext class and loadExt routine

git-svn-id: https://pykd.svn.codeplex.com/svn@70301 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\kernelnet_cp 2011-10-10 15:59:24 +00:00 committed by Mikhail I. Izmestev
parent a452624559
commit e064126853
6 changed files with 96 additions and 5 deletions

View File

@ -10,6 +10,7 @@
#include "dbgexcept.h" #include "dbgexcept.h"
#include "module.h" #include "module.h"
#include "dbgio.h" #include "dbgio.h"
#include "dbgcmd.h"
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
@ -69,6 +70,10 @@ public:
return Module( m_client, offset ); return Module( m_client, offset );
} }
DbgExtensionPtr loadExtension( const std::wstring &extPath ) {
return DbgExtensionPtr( new DbgExtension( m_client, extPath ) );
}
ULONG64 addr64( ULONG64 addr ); ULONG64 addr64( ULONG64 addr );
void dprint( const std::wstring &str, bool dml = false ); void dprint( const std::wstring &str, bool dml = false );

View File

@ -32,6 +32,53 @@ std::string dbgCommand( const std::wstring &command )
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
DbgExtension::DbgExtension( IDebugClient4 *client, const std::wstring &extPath ) :
DbgObject( client )
{
HRESULT hres;
hres = m_control->AddExtensionWide( extPath.c_str(), 0, &m_handle );
if ( FAILED( hres ) )
throw DbgException( "IDebugControl::AddExtension failed" );
}
/////////////////////////////////////////////////////////////////////////////////
DbgExtension::~DbgExtension()
{
m_control->RemoveExtension( m_handle );
}
/////////////////////////////////////////////////////////////////////////////////
std::string DbgExtension::call( const std::wstring &command, const std::wstring &params )
{
HRESULT hres;
OutputReader outReader( m_client );
PyThreadState *pystate = PyEval_SaveThread();
hres = m_control->CallExtensionWide( m_handle, command.c_str(), NULL );
PyEval_RestoreThread( pystate );
if ( FAILED( hres ) )
throw DbgException( "IDebugControl::CallExtension failed" );
return std::string( outReader.Line() );
}
/////////////////////////////////////////////////////////////////////////////////
DbgExtensionPtr
loadExtension( const std::wstring &extPath )
{
return g_dbgClient->loadExtension( extPath );
}
/////////////////////////////////////////////////////////////////////////////////
} // end namespace pykd } // end namespace pykd

View File

@ -1,5 +1,8 @@
#pragma once #pragma once
#include <string>
#include "dbgobj.h"
namespace pykd { namespace pykd {
@ -10,6 +13,30 @@ dbgCommand( const std::wstring &command );
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
class DbgExtension : private DbgObject {
public:
DbgExtension( IDebugClient4 *client, const std::wstring &extPath );
virtual ~DbgExtension();
std::string
call( const std::wstring &command, const std::wstring &param );
private:
ULONG64 m_handle;
};
typedef boost::shared_ptr<DbgExtension> DbgExtensionPtr;
DbgExtensionPtr
loadExtension( const std::wstring &extPath );
///////////////////////////////////////////////////////////////////////////////////
}; // end of namespace pykd }; // end of namespace pykd

View File

@ -65,6 +65,8 @@ BOOST_PYTHON_MODULE( pykd )
"Attach debugger to a exsisting process" ) "Attach debugger to a exsisting process" )
.def( "attachKernel", &pykd::DebugClient::attachKernel, .def( "attachKernel", &pykd::DebugClient::attachKernel,
"Attach debugger to a target's kernel" ) "Attach debugger to a target's kernel" )
.def ( "loadExt", &pykd::DebugClient::loadExtension,
"Load a debuger extension" )
.def( "loadModule", &pykd::DebugClient::loadModule, .def( "loadModule", &pykd::DebugClient::loadModule,
"Return instance of Module class" ) "Return instance of Module class" )
.def( "findModule", &pykd::DebugClient::findModule, .def( "findModule", &pykd::DebugClient::findModule,
@ -86,6 +88,8 @@ BOOST_PYTHON_MODULE( pykd )
"Attach debugger to a exsisting process" ); "Attach debugger to a exsisting process" );
python::def( "attachKernel", &pykd::attachKernel, python::def( "attachKernel", &pykd::attachKernel,
"Attach debugger to a kernel target" ); "Attach debugger to a kernel target" );
python::def( "loadExt", &pykd::loadExtension,
"Load a debuger extension" );
python::def( "loadModule", &pykd::loadModule, python::def( "loadModule", &pykd::loadModule,
"Return instance of Module class" ); "Return instance of Module class" );
python::def( "findModule", &pykd::findModule, python::def( "findModule", &pykd::findModule,
@ -128,11 +132,15 @@ BOOST_PYTHON_MODULE( pykd )
.def("__getattr__", &pykd::Module::getSymbol, .def("__getattr__", &pykd::Module::getSymbol,
"Return address of the symbol" ); "Return address of the symbol" );
boost::python::class_<DbgOut>( "dout", "dout", python::no_init ) python::class_<DbgOut>( "dout", "dout", python::no_init )
.def( "write", &DbgOut::write ); .def( "write", &pykd::DbgOut::write );
boost::python::class_<DbgIn>( "din", "din", python::no_init ) python::class_<DbgIn>( "din", "din", python::no_init )
.def( "readline", &DbgIn::readline ); .def( "readline", &pykd::DbgIn::readline );
python::class_<DbgExtension, pykd::DbgExtensionPtr>("ext", python::no_init )
.def( "call", &pykd::DbgExtension::call,
"Call debug extension command end return it's result as a string" );
python::def( "diaLoadPdb", &pyDia::GlobalScope::loadPdb, python::def( "diaLoadPdb", &pyDia::GlobalScope::loadPdb,
"Open pdb file for quering debug symbols. Return DiaSymbol of global scope"); "Open pdb file for quering debug symbols. Return DiaSymbol of global scope");

View File

@ -111,6 +111,7 @@ class BaseTest( unittest.TestCase ):
""" Branch test: new API 0.1.x what must be available """ """ Branch test: new API 0.1.x what must be available """
self.assertTrue( hasattr(pykd, 'createDbgClient') ) self.assertTrue( hasattr(pykd, 'createDbgClient') )
self.assertTrue( hasattr(pykd, 'diaLoadPdb') ) self.assertTrue( hasattr(pykd, 'diaLoadPdb') )
self.assertTrue( hasattr(pykd, 'loadExt') )
self.assertTrue( hasattr(pykd, 'DiaException') ) self.assertTrue( hasattr(pykd, 'DiaException') )
self.assertTrue( hasattr(pykd, 'DiaScope') ) self.assertTrue( hasattr(pykd, 'DiaScope') )

View File

@ -7,4 +7,7 @@ class DbgcmdTest( unittest.TestCase ):
def testDbgCommand( self ): def testDbgCommand( self ):
self.assertNotEqual( "", pykd.dbgCommand("lm") ) self.assertNotEqual( "", pykd.dbgCommand("lm") )
# def testDbgExt( self ):
# #ext = pykd.loadExt( "ext" )
# #self.assertNotEqual( "", ext.call("help", "") )