mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-29 20:03:33 +08:00
[pykd] fixed: issue 8657( !pycmd does not allow to define functions )
git-svn-id: https://pykd.svn.codeplex.com/svn@67703 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
parent
5d1bd33f62
commit
8e00dc3612
138
pykd/dbgext.cpp
138
pykd/dbgext.cpp
@ -788,52 +788,6 @@ pycmd( PDEBUG_CLIENT4 client, PCSTR args )
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
if ( !std::string( args ).empty() )
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
|
|
||||||
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 & )
|
|
||||||
{
|
|
||||||
// îøèáêà â ñêðèïòå
|
|
||||||
PyObject *errtype = NULL, *errvalue = NULL, *traceback = NULL;
|
|
||||||
|
|
||||||
PyErr_Fetch( &errtype, &errvalue, &traceback );
|
|
||||||
|
|
||||||
if(errvalue != NULL)
|
|
||||||
{
|
|
||||||
PyObject *s = PyObject_Str(errvalue);
|
|
||||||
|
|
||||||
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "%s\n", PyString_AS_STRING( s ) );
|
|
||||||
|
|
||||||
Py_DECREF(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
Py_XDECREF(errvalue);
|
|
||||||
Py_XDECREF(errtype);
|
|
||||||
Py_XDECREF(traceback);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
char str[100];
|
|
||||||
ULONG inputSize;
|
|
||||||
bool stopInput = false;
|
|
||||||
|
|
||||||
boost::python::import( "pykd" );
|
|
||||||
|
|
||||||
boost::python::object main = boost::python::import("__main__");
|
|
||||||
|
|
||||||
boost::python::object global(main.attr("__dict__"));
|
|
||||||
|
|
||||||
// ïåðåíàïðàâëåíèå ñòàíäàðòíûõ ïîòîêîâ ÂÂ
|
// ïåðåíàïðàâëåíèå ñòàíäàðòíûõ ïîòîêîâ ÂÂ
|
||||||
boost::python::object sys = boost::python::import("sys");
|
boost::python::object sys = boost::python::import("sys");
|
||||||
|
|
||||||
@ -843,57 +797,111 @@ pycmd( PDEBUG_CLIENT4 client, PCSTR args )
|
|||||||
dbgIn din;
|
dbgIn din;
|
||||||
sys.attr("stdin") = boost::python::object( din );
|
sys.attr("stdin") = boost::python::object( din );
|
||||||
|
|
||||||
do {
|
boost::python::object syntaxError = boost::python::import("exceptions").attr("SyntaxError");
|
||||||
|
|
||||||
std::string output;
|
std::string commandBuffer;
|
||||||
|
|
||||||
dbgExt->control->Output( DEBUG_OUTPUT_NORMAL, ">>>" );
|
bool commandCompleted = true;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
|
||||||
OutputReader outputReader( (IDebugClient*)client );
|
if ( commandCompleted )
|
||||||
|
|
||||||
HRESULT hres = dbgExt->control->Input( str, sizeof(str), &inputSize );
|
|
||||||
|
|
||||||
if ( FAILED( hres ) || std::string( str ) == "" )
|
|
||||||
{
|
{
|
||||||
stopInput = true;
|
dbgExt->control->Output( DEBUG_OUTPUT_NORMAL, ">>>" );
|
||||||
break;
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dbgExt->control->Output( DEBUG_OUTPUT_NORMAL, "..." );
|
||||||
}
|
}
|
||||||
|
|
||||||
} while( FALSE );
|
{
|
||||||
|
char str[100];
|
||||||
|
ULONG inputSize;
|
||||||
|
|
||||||
if ( !stopInput )
|
OutputReader outputReader( (IDebugClient*)client );
|
||||||
|
HRESULT hres = dbgExt->control->Input( str, sizeof(str), &inputSize );
|
||||||
|
|
||||||
|
if ( FAILED( hres ) )
|
||||||
|
throw;
|
||||||
|
|
||||||
|
if ( commandCompleted )
|
||||||
|
{
|
||||||
|
if ( std::string( str ) == "" )
|
||||||
|
break;
|
||||||
|
|
||||||
|
commandBuffer = str;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ( std::string( str ) == "" )
|
||||||
|
commandCompleted = true;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
commandBuffer.append("\n");
|
||||||
|
commandBuffer.append( str );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( commandCompleted )
|
||||||
|
{
|
||||||
try {
|
try {
|
||||||
|
|
||||||
boost::python::exec( str, WindbgGlobalSession::global(), WindbgGlobalSession::global() );
|
boost::python::exec( commandBuffer.c_str(), WindbgGlobalSession::global(), WindbgGlobalSession::global() );
|
||||||
|
|
||||||
|
commandBuffer.clear();
|
||||||
|
|
||||||
}
|
}
|
||||||
catch( boost::python::error_already_set const & )
|
catch( boost::python::error_already_set const & )
|
||||||
{
|
{
|
||||||
// îøèáêà â ñêðèïòå
|
|
||||||
PyObject *errtype = NULL, *errvalue = NULL, *traceback = NULL;
|
PyObject *errtype = NULL, *errvalue = NULL, *traceback = NULL;
|
||||||
|
|
||||||
PyErr_Fetch( &errtype, &errvalue, &traceback );
|
PyErr_Fetch( &errtype, &errvalue, &traceback );
|
||||||
|
|
||||||
if(errvalue != NULL)
|
if ( errtype && errvalue )
|
||||||
{
|
{
|
||||||
PyObject *s = PyObject_Str(errvalue);
|
boost::python::tuple errValueObj( boost::python::handle<>( boost::python::borrowed(errvalue) ) );
|
||||||
|
|
||||||
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "%s/n", PyString_AS_STRING( s ) );
|
PyObject *errvalueStr = PyObject_Str(errvalue);
|
||||||
|
|
||||||
Py_DECREF(s);
|
std::string errValueStr = boost::python::extract<std::string>( errvalueStr );
|
||||||
|
|
||||||
|
Py_XDECREF(errvalueStr);
|
||||||
|
|
||||||
|
if ( PyErr_GivenExceptionMatches( syntaxError.ptr(), errtype ) )
|
||||||
|
{
|
||||||
|
if ( errValueObj[0] == "unexpected EOF while parsing" )
|
||||||
|
{
|
||||||
|
commandCompleted = false;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "%s\n", errValueStr.c_str() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "%s\n", errValueStr.c_str() );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Py_XDECREF(errvalue);
|
Py_XDECREF(errvalue);
|
||||||
Py_XDECREF(errtype);
|
Py_XDECREF(errtype);
|
||||||
Py_XDECREF(traceback);
|
Py_XDECREF(traceback);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Py_XDECREF(errvalue);
|
||||||
|
Py_XDECREF(errtype);
|
||||||
|
Py_XDECREF(traceback);
|
||||||
|
|
||||||
} while( !stopInput );
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} while( true );
|
||||||
|
}
|
||||||
catch(...)
|
catch(...)
|
||||||
{
|
{
|
||||||
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "unexpected error" );
|
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "unexpected error" );
|
||||||
|
Loading…
Reference in New Issue
Block a user