mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-20 03:23:23 +08:00
[0.3.x] added : DbgOut.writedml method
[0.3.x] added : targetSystem.getProcessById git-svn-id: https://pykd.svn.codeplex.com/svn@90380 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
parent
633d304294
commit
041a58f6e0
115
pykd/pydbgio.h
115
pykd/pydbgio.h
@ -6,6 +6,41 @@
|
||||
|
||||
namespace pykd {
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline void dprint( const std::wstring &str, bool dml = false )
|
||||
{
|
||||
python::object sys = python::import("sys");
|
||||
|
||||
if (dml && PyObject_HasAttrString(python::object(sys.attr("stdout")).ptr(), "writedml"))
|
||||
sys.attr("stdout").attr("writedml")(str);
|
||||
else
|
||||
sys.attr("stdout").attr("write")( str );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline void dprintln( const std::wstring &str, bool dml = false )
|
||||
{
|
||||
pykd::dprint(str + L"\n", dml);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline void eprint( const std::wstring &str )
|
||||
{
|
||||
python::object sys = python::import("sys");
|
||||
sys.attr("stderr").attr("write")(str);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline void eprintln( const std::wstring &str )
|
||||
{
|
||||
pykd::eprint(str + L"\n");
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class DbgOut : public kdlib::windbg::WindbgOut
|
||||
@ -48,84 +83,4 @@ public:
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class SysDbgOut : public DbgOut
|
||||
{
|
||||
public:
|
||||
|
||||
SysDbgOut() {
|
||||
m_state = PyThreadState_Get();
|
||||
}
|
||||
|
||||
virtual void write( const std::wstring& str) {
|
||||
AutoSavePythonState pystate( &m_state );
|
||||
python::object sys = python::import("sys");
|
||||
sys.attr("stdout").attr("write")( str );
|
||||
}
|
||||
|
||||
virtual void writedml( const std::wstring& str) {
|
||||
AutoSavePythonState pystate( &m_state );
|
||||
python::object sys = python::import("sys");
|
||||
sys.attr("stdout").attr("write")(str);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
PyThreadState* m_state;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class SysDbgIn : public DbgIn
|
||||
{
|
||||
public:
|
||||
|
||||
SysDbgIn() {
|
||||
m_state = PyThreadState_Get();
|
||||
}
|
||||
|
||||
virtual std::wstring readline() {
|
||||
AutoSavePythonState pystate( &m_state );
|
||||
python::object sys = python::import("sys");
|
||||
return python::extract<std::wstring>( sys.attr("stdin").attr("readline") );
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
PyThreadState* m_state;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline void dprint( const std::wstring &str, bool dml = false )
|
||||
{
|
||||
AutoRestorePyState pystate;
|
||||
kdlib::dprint(str,dml);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline void dprintln( const std::wstring &str, bool dml = false )
|
||||
{
|
||||
AutoRestorePyState pystate;
|
||||
kdlib::dprintln(str,dml);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline void eprint( const std::wstring &str )
|
||||
{
|
||||
AutoRestorePyState pystate;
|
||||
kdlib::eprint(str);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline void eprintln( const std::wstring &str )
|
||||
{
|
||||
AutoRestorePyState pystate;
|
||||
kdlib::eprintln(str);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
|
@ -89,18 +89,8 @@ namespace pykd {
|
||||
|
||||
void initialize()
|
||||
{
|
||||
pykd::SysDbgOut *sysPykdOut = new pykd::SysDbgOut();
|
||||
pykd::SysDbgOut *sysPykdErr = new pykd::SysDbgOut();
|
||||
pykd::SysDbgIn *sysPykdIn = new pykd::SysDbgIn();
|
||||
|
||||
AutoRestorePyState pystate;
|
||||
|
||||
kdlib::initialize();
|
||||
|
||||
// èñïîëüçîâàòü âìåñòî êîíñîëè ïîòîêè èç sys
|
||||
kdlib::dbgout = sysPykdOut;
|
||||
kdlib::dbgerr = sysPykdErr;
|
||||
kdlib::dbgin = sysPykdIn;
|
||||
}
|
||||
|
||||
void remote_initialize( const std::wstring& remoteOptions )
|
||||
@ -204,6 +194,7 @@ BOOST_PYTHON_MODULE( pykd )
|
||||
// Python debug output console helper classes
|
||||
python::class_<DbgOut>( "dout", "dout", python::no_init )
|
||||
.def( "write", &DbgOut::write )
|
||||
.def( "writedml", &DbgOut::writedml)
|
||||
.def( "flush", &DbgOut::flush )
|
||||
.add_property( "encoding", &DbgOut::encoding );
|
||||
|
||||
@ -532,8 +523,10 @@ BOOST_PYTHON_MODULE( pykd )
|
||||
"Check if the target is current")
|
||||
.def("getNumberProcesses", TargetSystemAdapter::getNumberProcesses,
|
||||
"Return processed number of the target system")
|
||||
.def("process", TargetSystemAdapter::getProcessByIndex,
|
||||
.def("getProcess", TargetSystemAdapter::getProcessByIndex,
|
||||
"Return process by index")
|
||||
.def("getProcessById", TargetSystemAdapter::getProcessById,
|
||||
"Return process by id")
|
||||
.def("currentProcess", TargetSystemAdapter::getCurrentProcess,
|
||||
"Return current process")
|
||||
;
|
||||
@ -559,8 +552,10 @@ BOOST_PYTHON_MODULE( pykd )
|
||||
"Check if the target is current")
|
||||
.def("getNumberThreads", TargetProcessAdapter::getNumberThreads,
|
||||
"Return number of threads for this process" )
|
||||
.def("thread", TargetProcessAdapter::getThreadByIndex,
|
||||
.def("getThread", TargetProcessAdapter::getThreadByIndex,
|
||||
"Return thread by its index" )
|
||||
.def("getThreadById", TargetProcessAdapter::getThreadById,
|
||||
"Return thread by its index")
|
||||
.def("currentThread", TargetProcessAdapter::getCurrentThread,
|
||||
"Return current thread" )
|
||||
.def("getNumberBreakpoints", TargetProcessAdapter::getNumberBreakpoints,
|
||||
|
@ -75,6 +75,12 @@ struct TargetSystemAdapter {
|
||||
return system.getProcessByIndex(index);
|
||||
}
|
||||
|
||||
static kdlib::TargetProcessPtr getProcessById(kdlib::TargetSystem& system, kdlib::PROCESS_DEBUG_ID id)
|
||||
{
|
||||
AutoRestorePyState pystate;
|
||||
return system.getProcessById(id);
|
||||
}
|
||||
|
||||
static kdlib::TargetProcessPtr getCurrentProcess(kdlib::TargetSystem& system)
|
||||
{
|
||||
AutoRestorePyState pystate;
|
||||
@ -151,6 +157,12 @@ struct TargetProcessAdapter {
|
||||
return process.getThreadByIndex(index);
|
||||
}
|
||||
|
||||
static kdlib::TargetThreadPtr getThreadById(kdlib::TargetProcess& process, kdlib::THREAD_DEBUG_ID id)
|
||||
{
|
||||
AutoRestorePyState pystate;
|
||||
return process.getThreadById(id);
|
||||
}
|
||||
|
||||
static kdlib::TargetThreadPtr getCurrentThread(kdlib::TargetProcess& process)
|
||||
{
|
||||
AutoRestorePyState pystate;
|
||||
|
Loading…
Reference in New Issue
Block a user