[0.1.x] added : Module class ( Class representing executable module )

git-svn-id: https://pykd.svn.codeplex.com/svn@69867 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\kernelnet_cp 2011-09-19 07:05:22 +00:00 committed by Mikhail I. Izmestev
parent f241ea851b
commit e19c2df872
10 changed files with 167 additions and 11 deletions

View File

@ -17,6 +17,10 @@ DebugClient::DebugClient()
hres = m_client->QueryInterface( __uuidof(IDebugControl4), (void**)&m_control ); hres = m_client->QueryInterface( __uuidof(IDebugControl4), (void**)&m_control );
if ( FAILED( hres ) ) 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");
} }
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////

View File

@ -5,6 +5,7 @@
#include <dbghelp.h> #include <dbghelp.h>
#include "dbgexcept.h" #include "dbgexcept.h"
#include "module.h"
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
@ -28,10 +29,16 @@ public:
void attachKernel( const std::wstring &param ); void attachKernel( const std::wstring &param );
Module loadModule( const std::string &moduleName ) {
return Module( m_client, moduleName );
}
private: private:
CComPtr<IDebugClient5> m_client; CComPtr<IDebugClient5> m_client;
CComPtr<IDebugControl4> m_control; CComPtr<IDebugControl4> m_control;
CComPtr<IDebugSymbols3> m_symbols;
}; };
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////

View File

@ -82,10 +82,19 @@ BOOST_PYTHON_MODULE( pykd )
.def( "loadDump", &pykd::DebugClient::loadDump, "Load crash dump" ) .def( "loadDump", &pykd::DebugClient::loadDump, "Load crash dump" )
.def( "startProcess", &pykd::DebugClient::startProcess, "Start process for debugging" ) .def( "startProcess", &pykd::DebugClient::startProcess, "Start process for debugging" )
.def( "attachProcess", &pykd::DebugClient::attachProcess, "Attach debugger to a exsisting process" ) .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_<pykd::Module>("module", "Class representing executable module", python::no_init ) python::class_<pykd::Module>("module", "Class representing executable module", python::no_init )
.def( python::init<std::string>( "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, python::def( "diaOpenPdb", &pyDia::GlobalScope::openPdb,
"Open pdb file for quering debug symbols. Return DiaSymbol of global scope"); "Open pdb file for quering debug symbols. Return DiaSymbol of global scope");

41
pykd/dbgobj.h Normal file
View File

@ -0,0 +1,41 @@
#pragma once
#include <dbgeng.h>
#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<IDebugClient5> m_client;
CComPtr<IDebugControl4> m_control;
CComPtr<IDebugSymbols3> m_symbols;
};
///////////////////////////////////////////////////////////////////////////////////
}; // end of namespace pykd

View File

@ -1,5 +1,39 @@
#include "stdafx.h" #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 <boost/format.hpp> //#include <boost/format.hpp>
// //
//#include "dbgext.h" //#include "dbgext.h"

View File

@ -1,15 +1,41 @@
#pragma once #pragma once
#include <string>
#include "dbgobj.h"
namespace pykd { namespace pykd {
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
class Module { class Module : private DbgObject {
public: public:
Module( const std::string &moduleName ) 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;
}; };
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
@ -17,6 +43,15 @@ public:
}; };
//#include <string> //#include <string>
//#include <map> //#include <map>
// //

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="windows-1251"?> <?xml version="1.0" encoding="windows-1251"?>
<VisualStudioProject <VisualStudioProject
ProjectType="Visual C++" ProjectType="Visual C++"
Version="9.00" Version="9,00"
Name="pykd" Name="pykd"
ProjectGUID="{FE961905-666F-4908-A212-961465F46F13}" ProjectGUID="{FE961905-666F-4908-A212-961465F46F13}"
RootNamespace="pykd" RootNamespace="pykd"
@ -423,6 +423,10 @@
RelativePath=".\dbgexcept.h" RelativePath=".\dbgexcept.h"
> >
</File> </File>
<File
RelativePath=".\dbgobj.h"
>
</File>
<File <File
RelativePath=".\diawrapper.h" RelativePath=".\diawrapper.h"
> >

View File

@ -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() )

View File

@ -16,8 +16,6 @@ import typeinfo
import regtest import regtest
import moduletest import moduletest
print dir(pykd)
def getTestSuite( singleName = "" ): def getTestSuite( singleName = "" ):
if singleName == "": if singleName == "":
return unittest.TestSuite( return unittest.TestSuite(
@ -42,7 +40,7 @@ if __name__ == "__main__":
dbg.startProcess( targetAppPath ) dbg.startProcess( targetAppPath )
# pykd.go() # pykd.go()
# target.module = pykd.loadModule( target.moduleName ) target.module = dbg.loadModule( target.moduleName )
suite = getTestSuite() suite = getTestSuite()