[0.3.x] added : targetSystem.processes() (return list of processes for the target system)

[0.3.x] added : targetProcess.threads() (return list of threads for the target process)
[0.3.x] added : targetProcess.modules() (return list of modules for the target process)
[0.3.x] added : targetProcess.breakpoints() (return list of breakpoints for the target process)
[0.3.x] added : targetProcess.stack() (return the thread's stack trace)

git-svn-id: https://pykd.svn.codeplex.com/svn@90885 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\ussrhero_cp 2015-12-15 21:19:54 +00:00 committed by Mikhail I. Izmestev
parent 7f5c64e6c1
commit 3a39aa8f50
5 changed files with 117 additions and 4 deletions

View File

@ -236,6 +236,7 @@
<ClCompile Include="pymemaccess.cpp" /> <ClCompile Include="pymemaccess.cpp" />
<ClCompile Include="pymod.cpp" /> <ClCompile Include="pymod.cpp" />
<ClCompile Include="pymodule.cpp" /> <ClCompile Include="pymodule.cpp" />
<ClCompile Include="pyprocess.cpp" />
<ClCompile Include="pytypedvar.cpp" /> <ClCompile Include="pytypedvar.cpp" />
<ClCompile Include="pytypeinfo.cpp" /> <ClCompile Include="pytypeinfo.cpp" />
<ClCompile Include="stdafx.cpp"> <ClCompile Include="stdafx.cpp">

View File

@ -242,6 +242,9 @@
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\lib\native\src\boost_chrono.thread_clock.cpp"> <ClCompile Include="$(MSBuildThisFileDirectory)..\..\lib\native\src\boost_chrono.thread_clock.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="pyprocess.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="pykd.def"> <None Include="pykd.def">

View File

@ -534,7 +534,7 @@ BOOST_PYTHON_MODULE( pykd )
.def("__init__", python::make_constructor(&kdlib::TargetSystem::getCurrent)) .def("__init__", python::make_constructor(&kdlib::TargetSystem::getCurrent))
.def("__init__", python::make_constructor(&kdlib::TargetSystem::getByIndex)) .def("__init__", python::make_constructor(&kdlib::TargetSystem::getByIndex))
.def("getNumber", TargetSystemAdapter::getNumberSystems, .def("getNumber", TargetSystemAdapter::getNumberSystems,
"Retunr number of systems").staticmethod("getNumber") "Return number of systems").staticmethod("getNumber")
.def("getCurrent", TargetSystemAdapter::getCurrent, .def("getCurrent", TargetSystemAdapter::getCurrent,
"Return current target system").staticmethod("getCurrent") "Return current target system").staticmethod("getCurrent")
.def("getSystemById", TargetSystemAdapter::getSystemById, .def("getSystemById", TargetSystemAdapter::getSystemById,
@ -559,6 +559,8 @@ BOOST_PYTHON_MODULE( pykd )
"Return process by id") "Return process by id")
.def("currentProcess", TargetSystemAdapter::getCurrentProcess, .def("currentProcess", TargetSystemAdapter::getCurrentProcess,
"Return current process") "Return current process")
.def("processes", TargetSystemAdapter::getProcessesList,
"get list of processes for the target system")
; ;
python::class_<kdlib::TargetProcess, kdlib::TargetProcessPtr, boost::noncopyable>("targetProcess", "Class representing process in the target system", python::no_init ) python::class_<kdlib::TargetProcess, kdlib::TargetProcessPtr, boost::noncopyable>("targetProcess", "Class representing process in the target system", python::no_init )
@ -577,7 +579,7 @@ BOOST_PYTHON_MODULE( pykd )
.add_property("peb", TargetProcessAdapter::getPebOffset, .add_property("peb", TargetProcessAdapter::getPebOffset,
"Return PEB address" ) "Return PEB address" )
.add_property("exeName", TargetProcessAdapter::getExeName, .add_property("exeName", TargetProcessAdapter::getExeName,
"Return the process executbakle file name") "Return the process executable file name")
.def("isCurrent", TargetProcessAdapter::isCurrent, .def("isCurrent", TargetProcessAdapter::isCurrent,
"Check if the target is current") "Check if the target is current")
.def("getNumberThreads", TargetProcessAdapter::getNumberThreads, .def("getNumberThreads", TargetProcessAdapter::getNumberThreads,
@ -596,6 +598,12 @@ BOOST_PYTHON_MODULE( pykd )
"Return number of modules for this process" ) "Return number of modules for this process" )
.def("getModule", TargetProcessAdapter::getModuleByIndex, .def("getModule", TargetProcessAdapter::getModuleByIndex,
"Return a module object by it's index" ) "Return a module object by it's index" )
.def("threads", TargetProcessAdapter::getThreadList,
"Return list of threads for the target process")
.def("breakpoints", TargetProcessAdapter::getBreakpointsList,
"Return list of breakpoints for the target process")
.def("modules", TargetProcessAdapter::getModulesList,
"Return list of modules for the target process")
; ;
python::class_<kdlib::TargetThread, kdlib::TargetThreadPtr, boost::noncopyable>("targetThread", "Class representing process in the target system", python::no_init ) python::class_<kdlib::TargetThread, kdlib::TargetThreadPtr, boost::noncopyable>("targetThread", "Class representing process in the target system", python::no_init )
@ -606,9 +614,9 @@ BOOST_PYTHON_MODULE( pykd )
.def("getCurrent", TargetThreadAdapter::getCurrent, .def("getCurrent", TargetThreadAdapter::getCurrent,
"Return a current thread").staticmethod("getCurrent") "Return a current thread").staticmethod("getCurrent")
.def("getThreadById", TargetThreadAdapter::getThreadById, .def("getThreadById", TargetThreadAdapter::getThreadById,
"Return process by id").staticmethod("getThreadById") "Return thread by id").staticmethod("getThreadById")
.add_property("id", TargetThreadAdapter::getId, .add_property("id", TargetThreadAdapter::getId,
"Return thread id") "Return thread's id")
.add_property("systemID", TargetThreadAdapter::getSystemId, .add_property("systemID", TargetThreadAdapter::getSystemId,
"Retrun system thread ID ( TID )" ) "Retrun system thread ID ( TID )" )
.add_property("teb", TargetThreadAdapter::getTebOffset, .add_property("teb", TargetThreadAdapter::getTebOffset,
@ -617,6 +625,8 @@ BOOST_PYTHON_MODULE( pykd )
"Set this thread current") "Set this thread current")
.def("isCurrent", TargetThreadAdapter::isCurrent, .def("isCurrent", TargetThreadAdapter::isCurrent,
"Check if this thread is current") "Check if this thread is current")
.def("stack", TargetThreadAdapter::getStack,
"Get thread's stack tarce")
; ;
python::class_<kdlib::Module, kdlib::ModulePtr, python::bases<kdlib::NumBehavior>, boost::noncopyable>("module", "Class representing executable module", python::no_init ) python::class_<kdlib::Module, kdlib::ModulePtr, python::bases<kdlib::NumBehavior>, boost::noncopyable>("module", "Class representing executable module", python::no_init )

89
pykd/pyprocess.cpp Normal file
View File

@ -0,0 +1,89 @@
#include "stdafx.h"
#include "pyprocess.h"
#include "stladaptor.h"
namespace pykd {
///////////////////////////////////////////////////////////////////////////////
python::list TargetSystemAdapter::getProcessesList(kdlib::TargetSystem& system)
{
std::vector<kdlib::TargetProcessPtr> processLst;
do {
AutoRestorePyState pystate;
for ( unsigned long i = 0; i < system.getNumberProcesses(); ++i)
processLst.push_back(system.getProcessByIndex(i));
} while(false);
return vectorToList(processLst);
}
///////////////////////////////////////////////////////////////////////////////
python::list TargetProcessAdapter::getThreadList(kdlib::TargetProcess& process)
{
std::vector<kdlib::TargetThreadPtr> threadLst;
do {
AutoRestorePyState pystate;
for ( unsigned long i = 0; i < process.getNumberThreads(); ++i)
threadLst.push_back(process.getThreadByIndex(i));
} while(false);
return vectorToList(threadLst);
}
///////////////////////////////////////////////////////////////////////////////
python::list TargetProcessAdapter::getBreakpointsList(kdlib::TargetProcess& process)
{
std::vector<pykd::Breakpoint*> bpLst;
do {
AutoRestorePyState pystate;
for ( unsigned long i = 0; i < process.getNumberBreakpoints(); ++i)
bpLst.push_back(new Breakpoint(process.getBreakpoint(i)));
} while(false);
return vectorToList(bpLst);
}
///////////////////////////////////////////////////////////////////////////////
python::list TargetProcessAdapter::getModulesList(kdlib::TargetProcess& process)
{
std::vector<kdlib::ModulePtr > moduleLst;
do {
AutoRestorePyState pystate;
for ( unsigned long i = 0; i < process.getNumberModules(); ++i)
moduleLst.push_back(process.getModuleByIndex(i));
} while(false);
return vectorToList(moduleLst);
}
///////////////////////////////////////////////////////////////////////////////
python::list TargetThreadAdapter::getStack(kdlib::TargetThread& thread)
{
std::vector<kdlib::StackFramePtr > frameLst;
do {
AutoRestorePyState pystate;
kdlib::StackPtr stack = thread.getStack();
for (unsigned long i = 0; i < stack->getFrameCount(); ++i)
frameLst.push_back(stack->getFrame(i));
} while(false);
return vectorToList(frameLst);
}
///////////////////////////////////////////////////////////////////////////////
}

View File

@ -92,6 +92,8 @@ struct TargetSystemAdapter {
AutoRestorePyState pystate; AutoRestorePyState pystate;
return system.isCurrent(); return system.isCurrent();
} }
static python::list getProcessesList(kdlib::TargetSystem& system);
}; };
@ -204,6 +206,12 @@ struct TargetProcessAdapter {
AutoRestorePyState pystate; AutoRestorePyState pystate;
return process.getModuleByIndex(index); return process.getModuleByIndex(index);
} }
static python::list getThreadList(kdlib::TargetProcess& process);
static python::list getBreakpointsList(kdlib::TargetProcess& process);
static python::list getModulesList(kdlib::TargetProcess& process);
}; };
@ -262,6 +270,8 @@ struct TargetThreadAdapter {
AutoRestorePyState pystate; AutoRestorePyState pystate;
return thread.isCurrent(); return thread.isCurrent();
} }
static python::list getStack(kdlib::TargetThread& thread);
}; };
} // pykd namespace } // pykd namespace