From 5f0d7125a4dfe4fff13d44eb1bab5763b7867845 Mon Sep 17 00:00:00 2001 From: Aleksey R Date: Thu, 10 Jan 2019 20:08:14 +0300 Subject: [PATCH] add: addSyntheticModule, removeSyntheticModule --- kdlibcpp | 2 +- pykd/pydbgeng.cpp | 16 ++++++++++++++++ pykd/pydbgeng.h | 3 +++ pykd/pymod.cpp | 9 ++++++++- test/scripts/synsymtest.py | 12 ++++++++++++ 5 files changed, 40 insertions(+), 2 deletions(-) diff --git a/kdlibcpp b/kdlibcpp index 9126f44..7c3fcfb 160000 --- a/kdlibcpp +++ b/kdlibcpp @@ -1 +1 @@ -Subproject commit 9126f4406b47281a331c3022c24eb5de73ca828c +Subproject commit 7c3fcfbf80300cf100b6fe98d40662a1c56041b4 diff --git a/pykd/pydbgeng.cpp b/pykd/pydbgeng.cpp index b7d955c..a4a43f1 100644 --- a/pykd/pydbgeng.cpp +++ b/pykd/pydbgeng.cpp @@ -213,4 +213,20 @@ std::wstring printSyntheticSymbol(const kdlib::SyntheticSymbol& syntheticSymbol) /////////////////////////////////////////////////////////////////////////////// +void addSyntheticModule(kdlib::MEMOFFSET_64 base, unsigned long size, const std::wstring &name, const std::wstring &path /*= std::wstring{}*/) +{ + AutoRestorePyState pystate; + return kdlib::addSyntheticModule(base, size, name, path); +} + +/////////////////////////////////////////////////////////////////////////////// + +void removeSyntheticModule(kdlib::MEMOFFSET_64 base) +{ + AutoRestorePyState pystate; + return kdlib::removeSyntheticModule(base); +} + +/////////////////////////////////////////////////////////////////////////////// + } //end namespace pykd diff --git a/pykd/pydbgeng.h b/pykd/pydbgeng.h index 9c0ee19..18cfdc7 100644 --- a/pykd/pydbgeng.h +++ b/pykd/pydbgeng.h @@ -456,6 +456,9 @@ kdlib::SyntheticSymbol addSyntheticSymbol( kdlib::MEMOFFSET_64 offset, unsigned void removeSyntheticSymbol(const kdlib::SyntheticSymbol& syntheticSymbol); std::wstring printSyntheticSymbol(const kdlib::SyntheticSymbol& syntheticSymbol); +void addSyntheticModule(kdlib::MEMOFFSET_64 base, unsigned long size, const std::wstring &name, const std::wstring &path = std::wstring{}); +void removeSyntheticModule(kdlib::MEMOFFSET_64 base); + /////////////////////////////////////////////////////////////////////////////// } //end namespace pykd diff --git a/pykd/pymod.cpp b/pykd/pymod.cpp index ce981f1..e86e718 100644 --- a/pykd/pymod.cpp +++ b/pykd/pymod.cpp @@ -106,6 +106,8 @@ BOOST_PYTHON_FUNCTION_OVERLOADS( getTypeInfoProviderFromPdb_, pykd::getTypeInfoP BOOST_PYTHON_FUNCTION_OVERLOADS( getTypeInfoProviderFromSource_, pykd::getTypeInfoProviderFromSource, 1, 2); BOOST_PYTHON_FUNCTION_OVERLOADS(evalExpr_, pykd::evalExpr, 1, 3); +BOOST_PYTHON_FUNCTION_OVERLOADS( addSyntheticModule_, pykd::addSyntheticModule, 3, 4 ); + namespace pykd { void initialize() @@ -599,7 +601,6 @@ void pykd_init() python::def("appendSrcPath", pykd::appendSrcPath, "Append current source path"); - // synthetic symbol python::def("addSyntheticSymbol", pykd::addSyntheticSymbol, "The addSyntheticSymbol function adds a synthetic symbol to a module in the current process\n" @@ -607,6 +608,12 @@ void pykd_init() python::def( "removeSyntheticSymbol", pykd::removeSyntheticSymbol, "The removeSyntheticSymbol function removes a synthetic symbol from a module in the current proces" ); + // synthetic module + python::def("addSyntheticModule", pykd::addSyntheticModule, addSyntheticModule_(python::args("base", "size", "name", "path"), + "The addSyntheticModule function adds a synthetic module to the module list the debugger maintains for the current process")); + python::def("removeSyntheticModule", pykd::removeSyntheticModule, + "The removeSyntheticModule function removes a synthetic module from the module list the debugger maintains for the current process"); + // secondary callback data python::def("enumTagged", pykd::enumTagged, "Return the list of secondary callback data IDs (as a strings)" ); diff --git a/test/scripts/synsymtest.py b/test/scripts/synsymtest.py index be4d0a8..ad6e4bd 100644 --- a/test/scripts/synsymtest.py +++ b/test/scripts/synsymtest.py @@ -28,3 +28,15 @@ class SynSymTest(unittest.TestCase): self.assertRaises( pykd.DbgException, target.module.offset, "synSym2" ) self.assertRaises( pykd.DbgException, pykd.removeSyntheticSymbol, _synsym ) + + def testModule(self): + """Add and remove synthetic module""" + base = 64 * 1024 + + pykd.addSyntheticModule(base, 1024, "artificial_module1") + pykd.addSyntheticModule(base + 1024, 1024, "artificial_module2", "artificial_module2_path") + + pykd.removeSyntheticSymbol( pykd.addSyntheticSymbol(base, 1, "artificial_symbol") ) + + pykd.removeSyntheticModule(base + 1024) + pykd.removeSyntheticModule(base)