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 + +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