[0.1.x] fixed : issue #10181 ( exception information (!py) )

git-svn-id: https://pykd.svn.codeplex.com/svn@73328 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\kernelnet_cp 2012-01-20 07:10:44 +00:00 committed by Mikhail I. Izmestev
parent f6adbfa042
commit 701b604457

View File

@ -994,60 +994,21 @@ py( PDEBUG_CLIENT4 client, PCSTR args )
PyErr_NormalizeException( &errtype, &errvalue, &traceback ); PyErr_NormalizeException( &errtype, &errvalue, &traceback );
if(errvalue != NULL)
{
if ( PyErr_GivenExceptionMatches(errtype, PyExc_SyntaxError))
{
PyObject *filenamePtr = PyObject_GetAttrString(errvalue ,"filename" );
PyObject *filenameStr = PyUnicode_FromObject(filenamePtr);
PyObject *linenoPtr = PyObject_GetAttrString(errvalue ,"lineno");
PyObject *offsetPtr = PyObject_GetAttrString(errvalue ,"offset");
PyObject *msg = PyObject_GetAttrString(errvalue, "msg");
PyObject *msgStr = PyUnicode_FromObject(msg);
std::wstringstream sstr; std::wstringstream sstr;
sstr << std::endl << L"Syntax error" << std::endl;
sstr << std::endl << PyUnicode_AS_UNICODE( msgStr ) << std::endl << std::endl; python::object lst =
sstr << "Filename: " << PyUnicode_AS_UNICODE( filenameStr ); python::object( tracebackModule.attr("format_exception" ) )(
sstr << " Line: " << PyInt_AsLong( linenoPtr ); python::handle<>( errtype ),
sstr << " Pos: " << PyInt_AsLong( offsetPtr ); python::handle<>( python::allow_null( errvalue ) ),
sstr << std::endl; python::handle<>( python::allow_null( traceback ) ) );
sstr << std::endl << std::endl;
for ( long i = 0; i < python::len(lst); ++i )
sstr << std::wstring( python::extract<std::wstring>(lst[i]) ) << std::endl;
dbgClient->eprintln( sstr.str() ); dbgClient->eprintln( sstr.str() );
Py_XDECREF( linenoPtr );
Py_XDECREF( offsetPtr );
Py_XDECREF( msgStr );
Py_XDECREF( msg );
}
else
{
PyObject *errvalueStr= PyUnicode_FromObject(errvalue);
if ( errvalueStr )
{
dbgClient->eprintln( PyUnicode_AS_UNICODE( errvalueStr ) );
Py_DECREF(errvalueStr);
}
if ( traceback )
{
python::object traceObj( python::handle<>( python::borrowed( traceback ) ) );
dbgClient->eprintln( L"\nTraceback:" );
python::object pFunc( tracebackModule.attr("format_tb") );
python::list traceList( pFunc( traceObj ) );
for ( long i = 0; i < python::len(traceList); ++i )
dbgClient->eprintln( python::extract<std::wstring>(traceList[i]) );
}
}
}
Py_XDECREF(errvalue);
Py_XDECREF(errtype);
Py_XDECREF(traceback);
} }
} }