From 93f698a3a04198e2570fe5a7459e47e0d967a61a Mon Sep 17 00:00:00 2001
From: "SND\\kernelnet_cp"
 <SND\kernelnet_cp@9b283d60-5439-405e-af05-b73fd8c4d996>
Date: Mon, 11 Jul 2016 10:51:59 +0000
Subject: [PATCH] [0.3.x] added : __str__ operator for targetSystem,
 targetProcess, targetThread classed

git-svn-id: https://pykd.svn.codeplex.com/svn@91005 9b283d60-5439-405e-af05-b73fd8c4d996
---
 pykd/pymod.cpp     |  3 +++
 pykd/pyprocess.cpp | 36 ++++++++++++++++++++++++++++++++++++
 pykd/pyprocess.h   |  5 +++++
 3 files changed, 44 insertions(+)

diff --git a/pykd/pymod.cpp b/pykd/pymod.cpp
index 5007617..7185908 100644
--- a/pykd/pymod.cpp
+++ b/pykd/pymod.cpp
@@ -579,6 +579,7 @@ BOOST_PYTHON_MODULE( pykd )
             "Return current process")
         .def("processes", TargetSystemAdapter::getProcessesList,
             "get list of processes for the target system")
+        .def("__str__", TargetSystemAdapter::print)
         ;
 
     python::class_<kdlib::TargetProcess, kdlib::TargetProcessPtr, boost::noncopyable>("targetProcess", "Class representing process in the target system", python::no_init )
@@ -622,6 +623,7 @@ BOOST_PYTHON_MODULE( pykd )
             "Return list of breakpoints for the target process")
         .def("modules", TargetProcessAdapter::getModulesList,
             "Return list of modules for the target process")
+        .def("__str__", TargetProcessAdapter::print)
          ;
 
     python::class_<kdlib::TargetThread, kdlib::TargetThreadPtr, boost::noncopyable>("targetThread", "Class representing process in the target system", python::no_init )
@@ -657,6 +659,7 @@ BOOST_PYTHON_MODULE( pykd )
             "Check if this thread is current")
         .def("stack", TargetThreadAdapter::getStack,
             "Get thread's stack tarce")
+        .def("__str__", TargetThreadAdapter::print)
         ;
 
 	python::class_<kdlib::Module, kdlib::ModulePtr, python::bases<kdlib::NumBehavior>, boost::noncopyable>("module", "Class representing executable module", python::no_init)
diff --git a/pykd/pyprocess.cpp b/pykd/pyprocess.cpp
index 14434ad..52f1aa2 100644
--- a/pykd/pyprocess.cpp
+++ b/pykd/pyprocess.cpp
@@ -22,6 +22,18 @@ python::list TargetSystemAdapter::getProcessesList(kdlib::TargetSystem& system)
 
 ///////////////////////////////////////////////////////////////////////////////
 
+std::wstring TargetSystemAdapter::print(kdlib::TargetSystem& system)
+{
+    std::wstringstream   sstr;
+
+    sstr << "Target System:" << std::endl;
+    sstr << system.getDescription() << std::endl;
+
+    return sstr.str();
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
 python::list TargetProcessAdapter::getThreadList(kdlib::TargetProcess& process)
 {
     std::vector<kdlib::TargetThreadPtr>  threadLst;
@@ -67,6 +79,18 @@ python::list TargetProcessAdapter::getModulesList(kdlib::TargetProcess& process)
 
 ///////////////////////////////////////////////////////////////////////////////
 
+std::wstring TargetProcessAdapter::print(kdlib::TargetProcess& process)
+{
+    std::wstringstream sstr;
+
+    sstr << "Target Process:" << std::endl;
+    sstr << "PID: " << std::hex << process.getSystemId() << std::endl;
+    sstr << "Name: " << process.getExecutableName() << std::endl;
+    return sstr.str();
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
 python::list TargetThreadAdapter::getStack(kdlib::TargetThread& thread)
 {
 
@@ -85,5 +109,17 @@ python::list TargetThreadAdapter::getStack(kdlib::TargetThread& thread)
 
 ///////////////////////////////////////////////////////////////////////////////
 
+std::wstring TargetThreadAdapter::print(kdlib::TargetThread& thread)
+{
+    std::wstringstream sstr;
+
+    sstr << "Target Thread:" << std::endl;
+    sstr << "PID: " << std::hex << thread.getProcess()->getSystemId() << std::endl;
+    sstr << "TID: " << std::hex << thread.getSystemId() << std::endl;
+    return sstr.str();
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
 }
 
diff --git a/pykd/pyprocess.h b/pykd/pyprocess.h
index 26cd75c..8473315 100644
--- a/pykd/pyprocess.h
+++ b/pykd/pyprocess.h
@@ -94,6 +94,8 @@ struct TargetSystemAdapter {
     }
 
     static python::list getProcessesList(kdlib::TargetSystem& system);
+
+    static std::wstring print(kdlib::TargetSystem& system);
 };
 
 
@@ -212,6 +214,8 @@ struct TargetProcessAdapter {
     static python::list getBreakpointsList(kdlib::TargetProcess& process);
 
     static python::list getModulesList(kdlib::TargetProcess& process);
+
+    static std::wstring print(kdlib::TargetProcess& process);
 };
 
 
@@ -291,6 +295,7 @@ struct TargetThreadAdapter {
         return thread.getFrameOffset();
     }
 
+    static std::wstring print(kdlib::TargetThread& thread);
 };
 
 } // pykd namespace