From 181f1d82f609608d0f661a216aaa196060f15800 Mon Sep 17 00:00:00 2001
From: "SND\\ussrhero_cp"
 <SND\ussrhero_cp@9b283d60-5439-405e-af05-b73fd8c4d996>
Date: Thu, 24 Dec 2015 22:00:09 +0000
Subject: [PATCH] [0.3.x] added : targetThread.instructionOffset property
 (return an instruction pointer) [0.3.x] added : targetThread.frameOffset
 property (return a frame pointer) [0.3.x] added : targetThread.stackOffset
 property (return a stack pointer)

git-svn-id: https://pykd.svn.codeplex.com/svn@90895 9b283d60-5439-405e-af05-b73fd8c4d996
---
 pykd/pymod.cpp      | 12 ++++++++++++
 pykd/pyprocess.h    | 19 +++++++++++++++++++
 pykd/pytypedvar.cpp | 11 +++++++----
 pykd/pytypeinfo.cpp | 11 +++++++----
 4 files changed, 45 insertions(+), 8 deletions(-)

diff --git a/pykd/pymod.cpp b/pykd/pymod.cpp
index ea5ade0..7285ca0 100644
--- a/pykd/pymod.cpp
+++ b/pykd/pymod.cpp
@@ -621,6 +621,18 @@ BOOST_PYTHON_MODULE( pykd )
             "Retrun system thread ID ( TID )" )
         .add_property("teb", TargetThreadAdapter::getTebOffset,
             "Return TEB address" )
+        .add_property( "ip", TargetThreadAdapter::getIP, 
+            "instruction pointer" )
+        .add_property( "instructionOffset", TargetThreadAdapter::getIP,
+            "Return an instruction offset" )
+        .add_property( "fp", TargetThreadAdapter::getFP,
+            "frame pointer" )
+        .add_property( "frameOffset",TargetThreadAdapter::getFP,
+            "Return a frame's offset" )
+        .add_property( "sp", TargetThreadAdapter::getSP, 
+            "stack pointer" )
+        .add_property( "stackOffset", TargetThreadAdapter::getSP,
+            "Return a stack pointer" )
         .def("setCurrent", TargetThreadAdapter::setCurrent,
             "Set this thread current")
         .def("isCurrent", TargetThreadAdapter::isCurrent,
diff --git a/pykd/pyprocess.h b/pykd/pyprocess.h
index fe9b4bf..26cd75c 100644
--- a/pykd/pyprocess.h
+++ b/pykd/pyprocess.h
@@ -272,6 +272,25 @@ struct TargetThreadAdapter {
     }
 
     static python::list getStack(kdlib::TargetThread& thread);
+
+    static kdlib::MEMOFFSET_64  getIP(kdlib::TargetThread& thread)
+    {
+        AutoRestorePyState  pystate;
+        return thread.getInstructionOffset();
+    }
+   
+    static kdlib::MEMOFFSET_64  getSP(kdlib::TargetThread& thread)
+    {
+        AutoRestorePyState  pystate;
+        return thread.getStackOffset();
+    }
+
+    static kdlib::MEMOFFSET_64  getFP(kdlib::TargetThread& thread)
+    {
+        AutoRestorePyState  pystate;
+        return thread.getFrameOffset();
+    }
+
 };
 
 } // pykd namespace
diff --git a/pykd/pytypedvar.cpp b/pykd/pytypedvar.cpp
index ae4f67b..7e50771 100644
--- a/pykd/pytypedvar.cpp
+++ b/pykd/pytypedvar.cpp
@@ -1,6 +1,7 @@
 #include "stdafx.h"
 
 #include "pytypedvar.h"
+#include "kdlib/exceptions.h"
 
 namespace pykd {
 
@@ -100,8 +101,9 @@ python::list TypedVarAdapter::getFields( kdlib::TypedVar& typedVar )
 python::list TypedVarAdapter::getElementsDir(kdlib::TypedVar& typedVar)
 {
     std::list<std::wstring>  lst;
+    python::list pylst;
 
-    do {
+    try {
 
         AutoRestorePyState  pystate;
 
@@ -111,9 +113,10 @@ python::list TypedVarAdapter::getElementsDir(kdlib::TypedVar& typedVar)
             lst.push_back(name);
         }
 
-    } while (false);
-
-    python::list pylst;
+    } catch(kdlib::DbgException&)
+    {
+        return pylst;
+    }
 
     for (std::list<std::wstring>::const_iterator it = lst.begin(); it != lst.end(); ++it)
         pylst.append(*it);
diff --git a/pykd/pytypeinfo.cpp b/pykd/pytypeinfo.cpp
index 50f082e..84001e2 100644
--- a/pykd/pytypeinfo.cpp
+++ b/pykd/pytypeinfo.cpp
@@ -108,7 +108,9 @@ python::list TypeInfoAdapter::getElementDir(kdlib::TypeInfo &typeInfo)
 {
     std::list<std::wstring>  lst;
 
-    do {
+    python::list pylst;
+
+    try{
 
         AutoRestorePyState  pystate;
 
@@ -118,9 +120,10 @@ python::list TypeInfoAdapter::getElementDir(kdlib::TypeInfo &typeInfo)
             lst.push_back(name);
         }
 
-    } while (false);
-
-    python::list pylst;
+    } catch(kdlib::DbgException&)
+    {
+        return pylst;
+    }
 
     for (std::list<std::wstring>::const_iterator it = lst.begin(); it != lst.end(); ++it)
         pylst.append(*it);