[pykd] updated : move all code for input/output operation to dbgio.h/cpp

git-svn-id: https://pykd.svn.codeplex.com/svn@66396 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\kernelnet_cp 2011-06-07 16:13:05 +00:00
parent d70b95ec1e
commit 80eaf476cd
12 changed files with 121 additions and 120 deletions

View File

@ -5,7 +5,7 @@
#include "dbgext.h" #include "dbgext.h"
#include "dbgcmd.h" #include "dbgcmd.h"
#include "dbgexcept.h" #include "dbgexcept.h"
#include "dbgcallback.h" #include "dbgio.h"
#include "dbgsystem.h" #include "dbgsystem.h"
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////

View File

@ -7,7 +7,7 @@
#include <dbgeng.h> #include <dbgeng.h>
#include "dbgmodule.h" #include "dbgmodule.h"
#include "dbgcallback.h" #include "dbgio.h"
#include "dbgevent.h" #include "dbgevent.h"
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////

View File

@ -11,7 +11,6 @@
#include <boost/python/overloads.hpp> #include <boost/python/overloads.hpp>
#include "dbgext.h" #include "dbgext.h"
#include "dbgprint.h"
#include "dbgreg.h" #include "dbgreg.h"
#include "dbgtype.h" #include "dbgtype.h"
#include "dbgmodule.h" #include "dbgmodule.h"
@ -24,12 +23,12 @@
#include "dbgeventcb.h" #include "dbgeventcb.h"
#include "dbgcallback.h" #include "dbgcallback.h"
#include "dbgpath.h" #include "dbgpath.h"
#include "dbginput.h"
#include "dbgprocess.h" #include "dbgprocess.h"
#include "dbgsynsym.h" #include "dbgsynsym.h"
#include "dbgclient.h" #include "dbgclient.h"
#include "dbgevent.h" #include "dbgevent.h"
#include "dbgbreak.h" #include "dbgbreak.h"
#include "dbgio.h"
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
@ -41,8 +40,8 @@ dbgClient g_dbgClient;
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
BOOST_PYTHON_FUNCTION_OVERLOADS( dprint, DbgPrint::dprint, 1, 2 ) BOOST_PYTHON_FUNCTION_OVERLOADS( dprint, dbgPrint::dprint, 1, 2 )
BOOST_PYTHON_FUNCTION_OVERLOADS( dprintln, DbgPrint::dprintln, 1, 2 ) BOOST_PYTHON_FUNCTION_OVERLOADS( dprintln, dbgPrint::dprintln, 1, 2 )
BOOST_PYTHON_FUNCTION_OVERLOADS( loadCharsOv, loadChars, 2, 3 ) BOOST_PYTHON_FUNCTION_OVERLOADS( loadCharsOv, loadChars, 2, 3 )
BOOST_PYTHON_FUNCTION_OVERLOADS( loadWCharsOv, loadWChars, 2, 3 ) BOOST_PYTHON_FUNCTION_OVERLOADS( loadWCharsOv, loadWChars, 2, 3 )
@ -82,9 +81,9 @@ BOOST_PYTHON_MODULE( pykd )
"Check if script works in windbg context" ); "Check if script works in windbg context" );
boost::python::def( "symbolsPath", &dbgSymPath, boost::python::def( "symbolsPath", &dbgSymPath,
"Return symbol path" ); "Return symbol path" );
boost::python::def( "dprint", &DbgPrint::dprint, dprint( boost::python::args( "str", "dml" ), boost::python::def( "dprint", &dbgPrint::dprint, dprint( boost::python::args( "str", "dml" ),
"Print out string. If dml = True string is printed with dml highlighting ( only for windbg )") ); "Print out string. If dml = True string is printed with dml highlighting ( only for windbg )") );
boost::python::def( "dprintln", &DbgPrint::dprintln, dprintln( boost::python::args( "str", "dml" ), boost::python::def( "dprintln", &dbgPrint::dprintln, dprintln( boost::python::args( "str", "dml" ),
"Print out string and insert end of line symbol. If dml = True string is printed with dml highlighting ( only for windbg )" ) ); "Print out string and insert end of line symbol. If dml = True string is printed with dml highlighting ( only for windbg )" ) );
boost::python::def( "loadDump", &dbgLoadDump, boost::python::def( "loadDump", &dbgLoadDump,
"Load crash dump (only for console)"); "Load crash dump (only for console)");
@ -523,15 +522,15 @@ private:
main_namespace[ key ] = pykd_namespace[ key ]; main_namespace[ key ] = pykd_namespace[ key ];
} }
// ïåðåíàïðàâëåíèå ñòàíäàðòíûõ ïîòîêîâ ÂÂ //// ïåðåíàïðàâëåíèå ñòàíäàðòíûõ ïîòîêîâ ÂÂ
boost::python::object sys = boost::python::import( "sys"); //boost::python::object sys = boost::python::import( "sys");
//
dbgOut dout; //dbgOut dout;
sys.attr("stdout") = boost::python::object( dout ); //sys.attr("stdout") = boost::python::object( dout );
dbgIn din;
sys.attr("stdin") = boost::python::object( din );
//dbgIn din;
//sys.attr("stdin") = boost::python::object( din );
//
g_dbgClient.startEventsMgr(); g_dbgClient.startEventsMgr();
} }
@ -770,6 +769,7 @@ py( PDEBUG_CLIENT4 client, PCSTR args)
catch(...) catch(...)
{ {
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "unexpected error" );
} }
Py_EndInterpreter( localInterpreter ); Py_EndInterpreter( localInterpreter );
@ -784,17 +784,22 @@ HRESULT
CALLBACK CALLBACK
pycmd( PDEBUG_CLIENT4 client, PCSTR args ) pycmd( PDEBUG_CLIENT4 client, PCSTR args )
{ {
try { DbgExt ext( client );
DbgExt ext( client ); try {
if ( !std::string( args ).empty() ) if ( !std::string( args ).empty() )
{ {
try try {
{
OutputReader outputReader( dbgExt->client );
boost::python::exec( args, WindbgGlobalSession::global(), WindbgGlobalSession::global() ); boost::python::object retObj = boost::python::eval( args, WindbgGlobalSession::global(), WindbgGlobalSession::global() );
if ( retObj.ptr() != NULL )
{
PyObject *s = PyObject_Str( retObj.ptr() );
dbgExt->control->Output( DEBUG_OUTPUT_NORMAL, "%s\n", PyString_AS_STRING( s ) );
Py_DECREF( s );
}
} }
catch( boost::python::error_already_set const & ) catch( boost::python::error_already_set const & )
{ {
@ -831,7 +836,7 @@ pycmd( PDEBUG_CLIENT4 client, PCSTR args )
do { do {
OutputReader outputReader( (IDebugClient*)client ); OutputReader outputReader( (IDebugClient*)client );
HRESULT hres = dbgExt->control->Input( str, sizeof(str), &inputSize ); HRESULT hres = dbgExt->control->Input( str, sizeof(str), &inputSize );
@ -876,10 +881,10 @@ pycmd( PDEBUG_CLIENT4 client, PCSTR args )
catch(...) catch(...)
{ {
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "unexpected error" );
} }
return S_OK; return S_OK;
} }
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////

View File

@ -1,40 +0,0 @@
#pragma once
#include "dbgprint.h"
/////////////////////////////////////////////////////////////////////////////////
class dbgOut {
public:
void
write( const boost::python::object &str ) {
DbgPrint::dprint( str );
}
};
/////////////////////////////////////////////////////////////////////////////////
class dbgIn {
public:
std::string
readline() {
char str[100];
ULONG inputSize;
OutputReader outputReader( dbgExt->client );
dbgExt->control->Input( str, sizeof(str), &inputSize );
return std::string( str );
}
};
/////////////////////////////////////////////////////////////////////////////////

View File

@ -1,13 +1,16 @@
#include "stdafx.h" #include "stdafx.h"
#include <iostream> #include <iostream>
#include <Fcntl.h>
#include "dbgprint.h" #include "dbgio.h"
#include "dbgext.h" #include "dbgext.h"
using namespace std; using namespace std;
void DbgPrint::dprint( const boost::python::object& obj, bool dml ) /////////////////////////////////////////////////////////////////////////////////
void dbgPrint::dprint( const boost::python::object& obj, bool dml )
{ {
std::wstring str = boost::python::extract<std::wstring>( obj ); std::wstring str = boost::python::extract<std::wstring>( obj );
@ -16,7 +19,9 @@ void DbgPrint::dprint( const boost::python::object& obj, bool dml )
std::wcout << str; std::wcout << str;
} }
void DbgPrint::dprintln( const boost::python::object& obj, bool dml ) /////////////////////////////////////////////////////////////////////////////////
void dbgPrint::dprintln( const boost::python::object& obj, bool dml )
{ {
std::wstring str = boost::python::extract<std::wstring>( obj ); std::wstring str = boost::python::extract<std::wstring>( obj );
str += L"\r\n"; str += L"\r\n";
@ -26,3 +31,4 @@ void DbgPrint::dprintln( const boost::python::object& obj, bool dml )
std::wcout << str; std::wcout << str;
} }
/////////////////////////////////////////////////////////////////////////////////

View File

@ -1,9 +1,21 @@
#pragma once #pragma once
#include "dbgext.h" #include <string>
#include "dbgexcept.h" #include <dbgeng.h>
#include <wdbgexts.h> #include "dbgext.h"
/////////////////////////////////////////////////////////////////////////////////
class dbgPrint {
public:
static void dprint( const boost::python::object& obj, bool dml = false );
static void dprintln( const boost::python::object& obj, bool dml = false );
};
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -173,4 +185,40 @@ private:
}; };
///////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
class dbgOut {
public:
void
write( const boost::python::object &str ) {
dbgPrint::dprint( str );
}
};
/////////////////////////////////////////////////////////////////////////////////
class dbgIn {
public:
std::string
readline() {
char str[100];
ULONG inputSize;
OutputReader outputReader( dbgExt->client );
dbgExt->control->Input( str, sizeof(str), &inputSize );
return std::string( str );
}
};
/////////////////////////////////////////////////////////////////////////////////

View File

@ -7,7 +7,7 @@
#include "dbgexcept.h" #include "dbgexcept.h"
#include "dbgmem.h" #include "dbgmem.h"
#include "dbgsystem.h" #include "dbgsystem.h"
#include "dbgcallback.h" #include "dbgio.h"
using namespace std; using namespace std;

View File

@ -8,7 +8,7 @@
#include "dbgmodule.h" #include "dbgmodule.h"
#include "dbgexcept.h" #include "dbgexcept.h"
#include "dbgsym.h" #include "dbgsym.h"
#include "dbgcallback.h" #include "dbgio.h"
#include "dbgsynsym.h" #include "dbgsynsym.h"
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////

View File

@ -1,17 +0,0 @@
// âûâîä èíôîðìàöèè â îòëàä÷èê
#pragma once
#include <string>
class DbgPrint {
public:
static void dprint( const boost::python::object& obj, bool dml = false );
static void dprintln( const boost::python::object& obj, bool dml = false );
};

View File

@ -3,7 +3,6 @@
#include "dbgext.h" #include "dbgext.h"
#include "dbgsym.h" #include "dbgsym.h"
#include "dbgexcept.h" #include "dbgexcept.h"
#include "dbgprint.h"
#include "dbgmem.h" #include "dbgmem.h"
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////

View File

@ -6,7 +6,7 @@
#include "dbgext.h" #include "dbgext.h"
#include "dbgexcept.h" #include "dbgexcept.h"
#include "dbgsystem.h" #include "dbgsystem.h"
#include "dbgcallback.h" #include "dbgio.h"
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////

View File

@ -368,6 +368,10 @@
RelativePath=".\dbgdump.cpp" RelativePath=".\dbgdump.cpp"
> >
</File> </File>
<File
RelativePath=".\dbgevent.cpp"
>
</File>
<File <File
RelativePath=".\dbgeventcb.cpp" RelativePath=".\dbgeventcb.cpp"
> >
@ -381,11 +385,11 @@
> >
</File> </File>
<File <File
RelativePath=".\dbgmem.cpp" RelativePath=".\dbgio.cpp"
> >
</File> </File>
<File <File
RelativePath=".\dbgevent.cpp" RelativePath=".\dbgmem.cpp"
> >
</File> </File>
<File <File
@ -396,10 +400,6 @@
RelativePath=".\dbgpath.cpp" RelativePath=".\dbgpath.cpp"
> >
</File> </File>
<File
RelativePath=".\dbgprint.cpp"
>
</File>
<File <File
RelativePath=".\dbgprocess.cpp" RelativePath=".\dbgprocess.cpp"
> >
@ -474,10 +474,6 @@
RelativePath=".\dbgbreak.h" RelativePath=".\dbgbreak.h"
> >
</File> </File>
<File
RelativePath=".\dbgcallback.h"
>
</File>
<File <File
RelativePath=".\dbgclient.h" RelativePath=".\dbgclient.h"
> >
@ -490,6 +486,10 @@
RelativePath=".\dbgdump.h" RelativePath=".\dbgdump.h"
> >
</File> </File>
<File
RelativePath=".\dbgevent.h"
>
</File>
<File <File
RelativePath=".\dbgeventcb.h" RelativePath=".\dbgeventcb.h"
> >
@ -507,11 +507,11 @@
> >
</File> </File>
<File <File
RelativePath=".\dbgmem.h" RelativePath=".\dbgio.h"
> >
</File> </File>
<File <File
RelativePath=".\dbgevent.h" RelativePath=".\dbgmem.h"
> >
</File> </File>
<File <File