[0.1.x] added : syntax error output for !py command

git-svn-id: https://pykd.svn.codeplex.com/svn@71848 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\kernelnet_cp 2011-11-28 08:26:30 +00:00 committed by Mikhail I. Izmestev
parent 5ee21bec08
commit 2e618b08d8
2 changed files with 136 additions and 97 deletions

View File

@ -806,11 +806,43 @@ py( PDEBUG_CLIENT4 client, PCSTR args )
PyErr_Fetch( &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;
sstr << std::endl << L"Syntax error" << std::endl;
sstr << std::endl << PyUnicode_AS_UNICODE( msgStr ) << std::endl << std::endl;
sstr << "Filename: " << PyUnicode_AS_UNICODE( filenameStr );
sstr << " Line: " << PyInt_AsLong( linenoPtr );
sstr << " Pos: " << PyInt_AsLong( offsetPtr );
sstr << std::endl;
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 )
{
@ -824,8 +856,7 @@ py( PDEBUG_CLIENT4 client, PCSTR args )
for ( long i = 0; i < python::len(traceList); ++i )
dbgClient->eprintln( python::extract<std::wstring>(traceList[i]) );
}
Py_DECREF(errvalueStr);
}
}
Py_XDECREF(errvalue);

View File

@ -86,29 +86,37 @@ def parseMask(mask, maskSets) :
cnt += 1
return mask
argc = len(sys.argv)
def main():
if argc == 1 :
argc = len(sys.argv)
0/0
if argc == 1 :
dprintln("Syntax: [object type] <;hex mask>;")
dprintln("Supported object types: process, thread, file, generic")
quit( 0 )
return
type = (argc > 2 and sys.argv[1]) or "generic"
if argc > 2 :
type = (argc > 2 and sys.argv[1]) or "generic"
if argc > 2 :
mask = int(sys.argv[2], 16)
else :
else :
mask = int(sys.argv[1], 16)
if type == "file" :
if type == "file" :
mask = parseMask(mask, FileMaskSets)
elif type == "process" :
if type == "process" :
mask = parseMask(mask, ProcessMaskSets)
elif type == "thread" :
if type == "thread" :
mask = parseMask(mask, ThreadMaskSets)
elif type == "generic" :
elif type == "generic" :
mask = parseMask(mask, GenericMaskSets)
dprintln("")
dprintln("")
if mask != 0 :
if mask != 0 :
dprintln("Unknown bits: 0x%x" % mask)
if __name__ == "__main__":
main()