From 529794221ed707c3241817dfecc4f3315981a23d Mon Sep 17 00:00:00 2001
From: "SND\\kernelnet_cp"
 <SND\kernelnet_cp@9b283d60-5439-405e-af05-b73fd8c4d996>
Date: Tue, 29 Oct 2013 05:49:55 +0000
Subject: [PATCH] [0.3.x] added : pydbgio.h

git-svn-id: https://pykd.svn.codeplex.com/svn@86067 9b283d60-5439-405e-af05-b73fd8c4d996
---
 pykd/pydbgio.h | 45 +++++++++++++++++++++++++++++++++++++++++++++
 pykd/pystate.h | 27 +++++++++++++++++++++++++++
 2 files changed, 72 insertions(+)
 create mode 100644 pykd/pydbgio.h
 create mode 100644 pykd/pystate.h

diff --git a/pykd/pydbgio.h b/pykd/pydbgio.h
new file mode 100644
index 0000000..edc662f
--- /dev/null
+++ b/pykd/pydbgio.h
@@ -0,0 +1,45 @@
+#pragma once
+
+#include "kdlib/windbg.h"
+
+#include "pystate.h"
+
+namespace pykd {
+
+///////////////////////////////////////////////////////////////////////////////
+
+class DbgOut : public  kdlib::windbg::WindbgOut
+{
+public:
+
+    DbgOut() {
+        int a = 10;
+    }
+
+    void flush() {
+    }
+
+    std::wstring encoding() {
+        return L"ascii";
+    }
+};
+
+///////////////////////////////////////////////////////////////////////////////
+
+class DbgIn : public kdlib::windbg::WindbgIn
+{
+public:
+
+    std::wstring readline() {
+        AutoRestorePyState  pystate;
+        return kdlib::windbg::WindbgIn::readline();
+    }
+
+    std::wstring encoding() {
+        return L"ascii";
+    }
+};
+
+///////////////////////////////////////////////////////////////////////////////
+
+}
diff --git a/pykd/pystate.h b/pykd/pystate.h
new file mode 100644
index 0000000..e4f0dfa
--- /dev/null
+++ b/pykd/pystate.h
@@ -0,0 +1,27 @@
+
+#pragma once
+
+#include <Python.h>
+
+namespace pykd {
+
+class AutoRestorePyState 
+{
+public:
+
+    AutoRestorePyState() 
+    {
+        m_state =  PyEval_SaveThread();
+    }
+
+    ~AutoRestorePyState() 
+    {
+        PyEval_RestoreThread( m_state );
+    }
+
+private:
+
+    PyThreadState*    m_state;
+};
+
+}
\ No newline at end of file