diff --git a/pykd/dbgengine.cpp b/pykd/dbgengine.cpp new file mode 100644 index 0000000..3c47d9e --- /dev/null +++ b/pykd/dbgengine.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +#include "kdlib/dbgengine.h" + +#include "dbgengine.h" + +namespace pykd { + +/////////////////////////////////////////////////////////////////////////////// + +void targetGo() +{ + PyThreadState* state = PyEval_SaveThread(); + + kdlib::targetGo(); + + PyEval_RestoreThread( state ); +} + +/////////////////////////////////////////////////////////////////////////////// + +python::tuple getSourceLine( kdlib::MEMOFFSET_64 offset ) +{ + std::wstring fileName; + unsigned long lineno; + long displacement; + + kdlib::getSourceLine( fileName, lineno, displacement, offset ); + + return python::make_tuple( fileName, lineno, displacement ); +} + +/////////////////////////////////////////////////////////////////////////////// + +} //end namespace pykd diff --git a/pykd/target.h b/pykd/dbgengine.h similarity index 56% rename from pykd/target.h rename to pykd/dbgengine.h index d186f8d..71b3231 100644 --- a/pykd/target.h +++ b/pykd/dbgengine.h @@ -1,11 +1,18 @@ #pragma once +#include +namespace python = boost::python; + +#include "kdlib/dbgengine.h" + namespace pykd { /////////////////////////////////////////////////////////////////////////////// void targetGo(); +python::tuple getSourceLine( kdlib::MEMOFFSET_64 offset = 0 ); + /////////////////////////////////////////////////////////////////////////////// } //end namespace pykd \ No newline at end of file diff --git a/pykd/pykd.vcxproj b/pykd/pykd.vcxproj index 6e1c75a..a9632d2 100644 --- a/pykd/pykd.vcxproj +++ b/pykd/pykd.vcxproj @@ -123,12 +123,12 @@ + - @@ -136,6 +136,7 @@ + false @@ -154,7 +155,6 @@ Create Create - diff --git a/pykd/pykd.vcxproj.filters b/pykd/pykd.vcxproj.filters index 62822e7..5b7c9f4 100644 --- a/pykd/pykd.vcxproj.filters +++ b/pykd/pykd.vcxproj.filters @@ -30,9 +30,6 @@ Header Files - - Header Files - Header Files @@ -48,6 +45,9 @@ Header Files + + Header Files + @@ -62,10 +62,10 @@ Source Files - + Source Files - + Source Files diff --git a/pykd/pymod.cpp b/pykd/pymod.cpp index 5e97cf9..4c4544d 100644 --- a/pykd/pymod.cpp +++ b/pykd/pymod.cpp @@ -6,7 +6,7 @@ #include "variant.h" #include "module.h" -#include "target.h" +#include "dbgengine.h" #include "dbgexcept.h" #include "memaccess.h" #include "typeinfo.h" @@ -71,8 +71,8 @@ BOOST_PYTHON_FUNCTION_OVERLOADS( loadFloats_, loadFloats, 2, 3 ); BOOST_PYTHON_FUNCTION_OVERLOADS( loadDoubles_, loadDoubles, 2, 3 ); BOOST_PYTHON_FUNCTION_OVERLOADS( compareMemory_, kdlib::compareMemory, 3, 4 ); // -//BOOST_PYTHON_FUNCTION_OVERLOADS( getSourceLine_, getSourceLine, 0, 1 ); -//BOOST_PYTHON_FUNCTION_OVERLOADS( getSourceFile_, getSourceFile, 0, 1 ); +BOOST_PYTHON_FUNCTION_OVERLOADS( getSourceLine_, getSourceLine, 0, 1 ); +BOOST_PYTHON_FUNCTION_OVERLOADS( getSourceFile_, kdlib::getSourceFile, 0, 1 ); // //BOOST_PYTHON_FUNCTION_OVERLOADS( setSoftwareBp_, setSoftwareBp, 1, 2 ); //BOOST_PYTHON_FUNCTION_OVERLOADS( setHardwareBp_, setHardwareBp, 3, 4 ); @@ -238,13 +238,13 @@ BOOST_PYTHON_MODULE( pykd ) python::def( "loadDoubles", &loadDoubles, loadDoubles_( python::args( "offset", "count", "phyAddr" ), "Read the block of the target's memory and return it as list of doubles" ) ); - // // types and vaiables - // python::def( "getSourceFile", &getSourceFile, getSourceFile_( python::args( "offset"), - // "Return source file by the specified offset" ) ); - // python::def( "getSourceLine", &getSourceLine, getSourceLine_( python::args( "offset"), - // "Return source file name, line and displacement by the specified offset" ) ); - // python::def( "getOffset", &TypeInfo::getOffset, - // "Return traget virtual address for specified symbol" ); + // types and vaiables + python::def( "getSourceFile", &kdlib::getSourceFile, getSourceFile_( python::args( "offset"), + "Return source file by the specified offset" ) ); + python::def( "getSourceLine", &getSourceLine, getSourceLine_( python::args( "offset"), + "Return source file name, line and displacement by the specified offset" ) ); + python::def( "getOffset", &kdlib::getSymbolOffset, + "Return traget virtual address for specified symbol" ); // python::def( "findSymbol", &TypeInfo::findSymbol, findSymbol_( python::args( "offset", "showDisplacement"), // "Find symbol by the target virtual memory offset" ) ); // python::def("findSymbolAndDisp", &pysupport::findSymbolAndDisp, diff --git a/pykd/target.cpp b/pykd/target.cpp deleted file mode 100644 index a6bd44a..0000000 --- a/pykd/target.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "stdafx.h" - -#include "kdlib/dbgengine.h" - -#include "target.h" - -namespace pykd { - -/////////////////////////////////////////////////////////////////////////////// - -void targetGo() -{ - PyThreadState* state = PyEval_SaveThread(); - - kdlib::targetGo(); - - PyEval_RestoreThread( state ); -} - -/////////////////////////////////////////////////////////////////////////////// - -} //end namespace pykd diff --git a/test/scripts/memtest.py b/test/scripts/memtest.py index 600547c..f90585f 100644 --- a/test/scripts/memtest.py +++ b/test/scripts/memtest.py @@ -107,8 +107,8 @@ class MemoryTest( unittest.TestCase ): self.assertTrue( True ) def testPtrFloat(self): - self.assertTrue( math.fabs( pykd.ptrFloat( target.module.g_float) - 5.123456 ) < 0.001 ) - self.assertTrue( math.fabs( pykd.ptrDouble( target.module.g_double) - 5.1234567891 ) < 0.0000001 ) + self.assertTrue( math.fabs( pykd.ptrFloat( target.module.floatVar) + 5.99 ) < 0.001 ) + self.assertTrue( math.fabs( pykd.ptrDouble( target.module.doubleVar) - 6.00000001 ) < 0.0000001 ) def testLoadFloats(self): testArray = [ 1.0, 0.001, -199.999, 20000.01, 0.111111 ]; diff --git a/test/scripts/moduletest.py b/test/scripts/moduletest.py index 63d3aa7..3efebce 100644 --- a/test/scripts/moduletest.py +++ b/test/scripts/moduletest.py @@ -49,9 +49,9 @@ class ModuleTest( unittest.TestCase ): self.assertRaises( pykd.DbgException, pykd.module, target.module.end() + 0x10 ) def testSymbol( self ): - self.assertEqual( target.module.rva("FuncWithName0"), target.module.offset("FuncWithName0") - target.module.begin() ) - self.assertEqual( target.module.rva("FuncWithName0"), target.module.FuncWithName0 - target.module.begin() ) - self.assertEqual( target.module.rva("FuncWithName0"), pykd.getOffset( target.module.name() + "!FuncWithName0") - target.module.begin() ) + self.assertEqual( target.module.rva("FastcallFunc"), target.module.offset("FastcallFunc") - target.module.begin() ) + self.assertEqual( target.module.rva("FastcallFunc"), target.module.FastcallFunc - target.module.begin() ) + self.assertEqual( target.module.rva("FastcallFunc"), pykd.getOffset( target.module.name() + "!FastcallFunc") - target.module.begin() ) def testFindSymbol( self ): self.assertEqual( "LocalStaticFunc", target.module.findSymbol( target.module.offset("LocalStaticFunc") ) ) @@ -59,9 +59,6 @@ class ModuleTest( unittest.TestCase ): self.assertEqual( "StdcallFunc", target.module.findSymbol( target.module.offset("StdcallFunc") ) ) self.assertEqual( "FastcallFunc", target.module.findSymbol( target.module.offset("FastcallFunc") ) ) self.assertEqual( "_UnderscoreFunc", target.module.findSymbol( target.module.offset("_UnderscoreFunc") ) ) - - #self.assertEqual( "FuncWithName0", target.module.findSymbol( target.module.offset("FuncWithName0") ) ) - #self.assertEqual( "_FuncWithName2", target.module.findSymbol( target.module.offset("_FuncWithName2") ) ) #self.assertEqual( "targetapp!FuncWithName0", pykd.findSymbol( target.module.offset("FuncWithName0") ) ) #self.assertEqual( "targetapp!_FuncWithName2", pykd.findSymbol( target.module.offset("_FuncWithName2") ) ) #self.assertEqual( "_FuncWithName2+10", target.module.findSymbol( target.module.offset("_FuncWithName2") + 0x10 ) ) @@ -83,14 +80,14 @@ class ModuleTest( unittest.TestCase ): self.assertEqual( "structTest", target.module.type("g_structTest").name() ); def testSourceFile( self ): - fileName = pykd.getSourceFile(target.module.FuncWithName0 ) - self.assertTrue( re.search('targetapp\\.cpp', fileName ) ) - fileName, lineNo, displacement = pykd.getSourceLine( target.module.FuncWithName0 + 2) - self.assertEqual( 421, lineNo ) - self.assertTrue( re.search('targetapp\\.cpp', fileName ) ) + fileName = pykd.getSourceFile(target.module.CdeclFunc ) + self.assertTrue( re.search('testfunc\\.cpp', fileName ) ) + fileName, lineNo, displacement = pykd.getSourceLine( target.module.CdeclFunc + 2) + self.assertEqual( 15, lineNo ) + self.assertTrue( re.search('testfunc\\.cpp', fileName ) ) self.assertEqual( 2, displacement ) - fileName, lineNo, displacement = pykd.getSourceLine() - self.assertEqual( 698, lineNo ) + #fileName, lineNo, displacement = pykd.getSourceLine() + #self.assertEqual( 698, lineNo ) def testEnumSymbols( self ): lst = target.module.enumSymbols()