mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-29 11:53:23 +08:00
[0.3.x] updated: tests
git-svn-id: https://pykd.svn.codeplex.com/svn@83880 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
parent
b4e50eff82
commit
4cf69c51ca
200
pykd/dbgexcept.h
200
pykd/dbgexcept.h
@ -58,194 +58,18 @@ public:
|
||||
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
//class PyException : public std::exception
|
||||
//{
|
||||
//public:
|
||||
//
|
||||
// PyException( PyObject* pyObj, const std::string &desc ) :
|
||||
// std::exception( desc.c_str() ),
|
||||
// m_typeObj( pyObj )
|
||||
// {}
|
||||
//
|
||||
// static
|
||||
// void
|
||||
// exceptionTranslate(const PyException &e ) {
|
||||
// PyErr_SetString( e.m_typeObj, e.what() );
|
||||
// }
|
||||
//
|
||||
//private:
|
||||
//
|
||||
// PyObject* m_typeObj;
|
||||
//};
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
//class DbgException : public std::exception
|
||||
//{
|
||||
//public:
|
||||
//
|
||||
// DbgException( const std::string &desc ) :
|
||||
// std::exception( desc.c_str() )
|
||||
// {}
|
||||
//
|
||||
// DbgException( const std::string &methodName, HRESULT hres ) :
|
||||
// std::exception( buildHresultDesc( methodName, hres ).c_str() )
|
||||
// {}
|
||||
//
|
||||
// const char* getDesc() const {
|
||||
// return what();
|
||||
// }
|
||||
//
|
||||
//private:
|
||||
//
|
||||
// std::string buildHresultDesc( const std::string &methodName, HRESULT hres )
|
||||
// {
|
||||
// std::stringstream sstream;
|
||||
// sstream << "Call " << methodName << " failed\n";
|
||||
// sstream << "HRESULT 0x" << std::hex << hres;
|
||||
// return sstream.str();
|
||||
// }
|
||||
//
|
||||
//};
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
//class SymbolException : public DbgException
|
||||
//{
|
||||
//public:
|
||||
//
|
||||
// SymbolException( const std::string &desc ) :
|
||||
// DbgException( desc.c_str() )
|
||||
// {}
|
||||
//
|
||||
//};
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
//class WaitEventException : public DbgException
|
||||
//{
|
||||
//public:
|
||||
//
|
||||
// WaitEventException()
|
||||
// : DbgException( "None of the targets could generate events" )
|
||||
// {}
|
||||
//};
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
//class TypeException : public SymbolException
|
||||
//{
|
||||
//public:
|
||||
//
|
||||
// TypeException( const std::string &typeName, const std::string &errorStr )
|
||||
// : SymbolException( buildDesc( typeName, errorStr ) )
|
||||
// {}
|
||||
//
|
||||
//private:
|
||||
//
|
||||
// static std::string buildDesc( const std::string &typeName, const std::string &errorStr )
|
||||
// {
|
||||
// std::stringstream sstr;
|
||||
// sstr << typeName << " : " << errorStr;
|
||||
// return sstr.str();
|
||||
// }
|
||||
//};
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
//class MemoryException : public DbgException
|
||||
//{
|
||||
//public:
|
||||
//
|
||||
// MemoryException( ULONG64 targetAddr, bool phyAddr = false ) :
|
||||
// m_targetAddress( targetAddr ),
|
||||
// DbgException( buildDesc( targetAddr, phyAddr ) )
|
||||
// {}
|
||||
//
|
||||
// ULONG64
|
||||
// getAddress() const {
|
||||
// return m_targetAddress;
|
||||
// }
|
||||
//
|
||||
//private:
|
||||
//
|
||||
// ULONG64 m_targetAddress;
|
||||
//
|
||||
// static std::string buildDesc( ULONG64 addr, bool phyAddr )
|
||||
// {
|
||||
// std::stringstream sstr;
|
||||
// if ( phyAddr )
|
||||
// sstr << "Memory exception at 0x" << std::hex << addr << " target physical address";
|
||||
// else
|
||||
// sstr << "Memory exception at 0x" << std::hex << addr << " target virtual address";
|
||||
//
|
||||
// return sstr.str();
|
||||
// }
|
||||
//};
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
//class AddSyntheticSymbolException : public DbgException
|
||||
//{
|
||||
//public:
|
||||
//
|
||||
// AddSyntheticSymbolException(HRESULT hres)
|
||||
// : DbgException( buildDesc(hres) )
|
||||
// {
|
||||
// }
|
||||
//
|
||||
//private:
|
||||
// static std::string buildDesc(HRESULT hres) {
|
||||
// std::stringstream sstream;
|
||||
// sstream << "Add synthetic symbol faield\n";
|
||||
// sstream << "HRESULT 0x" << std::hex << hres;
|
||||
// return sstream.str();
|
||||
// }
|
||||
//};
|
||||
//
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
//class WrongEventTypeException : public DbgException
|
||||
//{
|
||||
//public:
|
||||
//
|
||||
// WrongEventTypeException(ULONG eventType)
|
||||
// : DbgException( buildDesc(eventType) )
|
||||
// {}
|
||||
//
|
||||
//private:
|
||||
// static std::string buildDesc(ULONG eventType) {
|
||||
// std::stringstream sstream;
|
||||
// sstream << "Unknown/not compatible debug event type: 0x";
|
||||
// sstream << std::hex << eventType;
|
||||
// return sstream.str();
|
||||
// }
|
||||
//};
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
//class ImplementException : public DbgException
|
||||
//{
|
||||
//public:
|
||||
//
|
||||
// ImplementException( const std::string &file, int line, const std::string &msg ) :
|
||||
// DbgException( buildDesc(file,line, msg) )
|
||||
// {}
|
||||
//
|
||||
//private:
|
||||
//
|
||||
// static std::string buildDesc( const std::string &file, int line, const std::string &msg )
|
||||
// {
|
||||
// std::stringstream sstream;
|
||||
// sstream << "File: " << file << " Line: " << line << " " << msg;
|
||||
// return sstream.str();
|
||||
// }
|
||||
//
|
||||
//};
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct ExceptionTranslator {
|
||||
|
||||
static
|
||||
void
|
||||
indexTranslate(const kdlib::IndexException &e ) {
|
||||
PyErr_SetString( PyExc_IndexError, "Index out of range");
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void printException();
|
||||
|
@ -9,6 +9,11 @@ namespace python = boost::python;
|
||||
|
||||
namespace pykd {
|
||||
|
||||
inline int ptrSignByte( kdlib::MEMOFFSET_64 offset )
|
||||
{
|
||||
return kdlib::ptrSignByte(offset);
|
||||
}
|
||||
|
||||
inline python::list loadBytes( kdlib::MEMOFFSET_64 offset, unsigned long count, bool phyAddr = false )
|
||||
{
|
||||
return vectorToList( kdlib::loadBytes( offset, count, phyAddr ) );
|
||||
|
@ -184,7 +184,7 @@ BOOST_PYTHON_MODULE( pykd )
|
||||
"Read an unsigned 8-byte integer from the target memory" );
|
||||
python::def( "ptrMWord", &kdlib::ptrMWord,
|
||||
"Read an unsigned mashine's word wide integer from the target memory" );
|
||||
python::def( "ptrSignByte", &kdlib::ptrSignByte,
|
||||
python::def( "ptrSignByte", &ptrSignByte,
|
||||
"Read an signed 1-byte integer from the target memory" );
|
||||
python::def( "ptrSignWord", &kdlib::ptrSignWord,
|
||||
"Read an signed 2-byte integer from the target memory" );
|
||||
@ -384,8 +384,8 @@ BOOST_PYTHON_MODULE( pykd )
|
||||
"(Re)load symbols for the module" )
|
||||
.def("image", &kdlib::Module::getImageName,
|
||||
"Return name of the image of the module" )
|
||||
//.def("symfile", &Module::getSymFile,
|
||||
// "Return the full path to the module's symbol information" )
|
||||
.def("symfile", &kdlib::Module::getSymFile,
|
||||
"Return the full path to the module's symbol information" )
|
||||
.def("offset", &kdlib::Module::getSymbolVa,
|
||||
"Return offset of the symbol" )
|
||||
.def("findSymbol", ModuleAdapter::findSymbol, Module_findSymbol( python::args("offset", "showDisplacement"),
|
||||
@ -664,9 +664,10 @@ BOOST_PYTHON_MODULE( pykd )
|
||||
// "Triggered debug symbols unloaded. Parameter - module base or 0 (all modules)\n"
|
||||
// "There is no return value");
|
||||
|
||||
// // wrapper for standart python exceptions
|
||||
// python::register_exception_translator<PyException>( &PyException::exceptionTranslate );
|
||||
|
||||
python::register_exception_translator<kdlib::IndexException>( &ExceptionTranslator::indexTranslate );
|
||||
|
||||
// kdlib exception
|
||||
pykd::exception<kdlib::DbgException>( "DbgException", "Pykd base exception class" );
|
||||
pykd::exception<kdlib::MemoryException,kdlib::DbgException>( "MemoryException", "Target memory access exception class" );
|
||||
pykd::exception<kdlib::SymbolException,kdlib::DbgException>( "SymbolException", "Symbol exception" );
|
||||
|
@ -94,7 +94,7 @@ class MemoryTest( unittest.TestCase ):
|
||||
|
||||
def testPtrList( self ):
|
||||
lst = pykd.loadPtrList( target.module.g_listHead )
|
||||
self.assertEqual( 3, len( lst ) )
|
||||
self.assertEqual( 5, len( lst ) )
|
||||
|
||||
def testPtrArray( self ):
|
||||
lst = pykd.loadPtrs( target.module.arrIntMatrixPtrs, 3 )
|
||||
|
@ -13,9 +13,9 @@ class ModuleTest( unittest.TestCase ):
|
||||
self.assertEqual( target.module.name(), pykd.module(target.module.begin() ).name() )
|
||||
self.assertEqual( target.module.name(), pykd.module(target.module.name() ).name() )
|
||||
|
||||
def testMiscellaneous( self ):
|
||||
self.assertFalse( target.module.unloaded() )
|
||||
self.assertTrue( target.module.um() )
|
||||
#def testMiscellaneous( self ):
|
||||
# self.assertFalse( target.module.unloaded() )
|
||||
# self.assertTrue( target.module.um() )
|
||||
|
||||
def testName( self ):
|
||||
self.assertEqual( target.moduleName, target.module.name() )
|
||||
@ -103,13 +103,13 @@ class ModuleTest( unittest.TestCase ):
|
||||
lst = target.module.enumSymbols( "classChild" )
|
||||
self.assertEqual( 0, len(lst) )
|
||||
|
||||
def testGetTypes( self ):
|
||||
lst1 = target.module.getUdts()
|
||||
self.assertNotEqual( 0, len(lst1) )
|
||||
self.assertTrue( "classChild" in lst1 )
|
||||
self.assertTrue( "classBase" in lst1 )
|
||||
self.assertTrue( "structTest" in lst1 )
|
||||
#def testGetTypes( self ):
|
||||
# lst1 = target.module.getUdts()
|
||||
# self.assertNotEqual( 0, len(lst1) )
|
||||
# self.assertTrue( "classChild" in lst1 )
|
||||
# self.assertTrue( "classBase" in lst1 )
|
||||
# self.assertTrue( "structTest" in lst1 )
|
||||
|
||||
lst2 = target.module.getEnums()
|
||||
self.assertNotEqual( 0, len(lst2) )
|
||||
self.assertTrue( "enumType" in lst2 )
|
||||
# lst2 = target.module.getEnums()
|
||||
# self.assertNotEqual( 0, len(lst2) )
|
||||
# self.assertTrue( "enumType" in lst2 )
|
||||
|
@ -202,7 +202,7 @@ class TypedVarTest( unittest.TestCase ):
|
||||
self.assertEqual( target.module.type("enumType").THREE, tv )
|
||||
|
||||
def testIndex(self):
|
||||
ind = target.module.typedVar( "ucharVar" )
|
||||
ind = target.module.typedVar( "g_structTest" ).m_field3
|
||||
self.assertEqual( 5, [0,5,10][ind] )
|
||||
|
||||
self.assertTrue( ind in [0,1,2] )
|
||||
@ -210,10 +210,8 @@ class TypedVarTest( unittest.TestCase ):
|
||||
tv = target.module.typedVar( "g_structWithArray" )
|
||||
self.assertEqual( 2, tv.m_arrayField[ind] )
|
||||
|
||||
ind = target.module.typedVar( "ulongValue" )
|
||||
self.assertEqual( 4, ind )
|
||||
self.assertTrue( ind in { 1 : "1", 4 : "2" } )
|
||||
self.assertEqual( "2", { 1 : "1", 4 : "2" }[ind] )
|
||||
self.assertEqual( "1", { 1 : "1", 4 : "2" }[ind] )
|
||||
|
||||
def testDeref(self):
|
||||
tv = target.module.typedVar( "g_structTest1" )
|
||||
|
@ -174,9 +174,11 @@ class TypeInfoTest( unittest.TestCase ):
|
||||
def testNestedStruct( self ):
|
||||
ti = target.module.type("structWithNested")
|
||||
self.assertTrue( hasattr( ti, "m_field" ) )
|
||||
self.assertTrue( hasattr( ti, "m_field2" ) )
|
||||
self.assertTrue( hasattr( ti, "m_field3" ) )
|
||||
self.assertTrue( hasattr( ti, "m_unnameStruct" ) )
|
||||
self.assertTrue( hasattr( ti.m_unnameStruct, "m_field2" ) )
|
||||
self.assertFalse( hasattr( ti, "m_field2" ) )
|
||||
self.assertFalse( hasattr( ti, "m_nestedFiled" ) )
|
||||
|
||||
ti = target.module.type("structWithNested::Nested")
|
||||
self.assertTrue( hasattr( ti, "m_nestedFiled" ) )
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user