[!] fixed : issue #8236 ( dprint/dprintln/print doesn't work with unicode string )

git-svn-id: https://pykd.svn.codeplex.com/svn@60725 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\kernelnet_cp 2011-01-26 16:17:33 +00:00
parent 1afb67fd2e
commit 8cab8ae27d
5 changed files with 32 additions and 27 deletions

View File

@ -71,6 +71,8 @@ private:
WindbgGlobalSession *windbgGlobalSession = NULL; WindbgGlobalSession *windbgGlobalSession = NULL;
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
BOOST_PYTHON_FUNCTION_OVERLOADS( dprint, DbgPrint::dprint, 1, 2 )
BOOST_PYTHON_FUNCTION_OVERLOADS( dprintln, DbgPrint::dprintln, 1, 2 )
BOOST_PYTHON_FUNCTION_OVERLOADS( loadBytes, loadArray<unsigned char>, 2, 3 ) BOOST_PYTHON_FUNCTION_OVERLOADS( loadBytes, loadArray<unsigned char>, 2, 3 )
BOOST_PYTHON_FUNCTION_OVERLOADS( loadWords, loadArray<unsigned short>, 2, 3 ) BOOST_PYTHON_FUNCTION_OVERLOADS( loadWords, loadArray<unsigned short>, 2, 3 )
@ -92,8 +94,8 @@ BOOST_PYTHON_MODULE( pykd )
boost::python::def( "createSession", &dbgCreateSession ); boost::python::def( "createSession", &dbgCreateSession );
boost::python::def( "isSessionStart", &dbgIsSessionStart ); boost::python::def( "isSessionStart", &dbgIsSessionStart );
boost::python::def( "symbolsPath", &dbgSymPath ); boost::python::def( "symbolsPath", &dbgSymPath );
boost::python::def( "dprint", &DbgPrint::dprint ); boost::python::def( "dprint", &DbgPrint::dprint, dprint( boost::python::args( "str", "dml" ), "" ) );
boost::python::def( "dprintln", &DbgPrint::dprintln ); boost::python::def( "dprintln", &DbgPrint::dprintln, dprintln( boost::python::args( "str", "dml" ), "" ) );
boost::python::def( "loadDump", &dbgLoadDump ); boost::python::def( "loadDump", &dbgLoadDump );
boost::python::def( "dbgCommand", &dbgCommand ); boost::python::def( "dbgCommand", &dbgCommand );
boost::python::def( "is64bitSystem", &is64bitSystem ); boost::python::def( "is64bitSystem", &is64bitSystem );
@ -110,7 +112,7 @@ BOOST_PYTHON_MODULE( pykd )
boost::python::def( "getOffset", &findAddressForSymbol ); boost::python::def( "getOffset", &findAddressForSymbol );
boost::python::def( "findModule", &findModule ); boost::python::def( "findModule", &findModule );
boost::python::def( "addr64", &addr64 ); boost::python::def( "addr64", &addr64 );
boost::python::def( "loadBytes", loadArray<unsigned char>, loadBytes( boost::python::args( "address", "number", "phyAddr" ), "" ) ); boost::python::def( "loadBytes", &loadArray<unsigned char>, loadBytes( boost::python::args( "address", "number", "phyAddr" ), "" ) );
boost::python::def( "loadWords", &loadArray<unsigned short>, loadWords( boost::python::args( "address", "number", "phyAddr" ), "" ) ); boost::python::def( "loadWords", &loadArray<unsigned short>, loadWords( boost::python::args( "address", "number", "phyAddr" ), "" ) );
boost::python::def( "loadDWords", &loadArray<unsigned long>, loadDWords( boost::python::args( "address", "number", "phyAddr" ), "" ) ); boost::python::def( "loadDWords", &loadArray<unsigned long>, loadDWords( boost::python::args( "address", "number", "phyAddr" ), "" ) );
boost::python::def( "loadQWords", &loadArray<unsigned __int64>, loadQWords( boost::python::args( "address", "number", "phyAddr" ), "" ) ); boost::python::def( "loadQWords", &loadArray<unsigned __int64>, loadQWords( boost::python::args( "address", "number", "phyAddr" ), "" ) );
@ -222,6 +224,7 @@ SetupDebugEngine( IDebugClient4 *client, DbgExt *dbgExt )
client->QueryInterface( __uuidof(IDebugControl), (void **)&dbgExt->control ); client->QueryInterface( __uuidof(IDebugControl), (void **)&dbgExt->control );
client->QueryInterface( __uuidof(IDebugControl4), (void **)&dbgExt->control4 );
client->QueryInterface( __uuidof(IDebugRegisters), (void **)&dbgExt->registers ); client->QueryInterface( __uuidof(IDebugRegisters), (void **)&dbgExt->registers );
@ -331,7 +334,7 @@ py( PDEBUG_CLIENT4 client, PCSTR args)
{ {
PyObject *s = PyObject_Str(errvalue); PyObject *s = PyObject_Str(errvalue);
DbgPrint::dprintln( PyString_AS_STRING( s ) ); dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "%s/n", PyString_AS_STRING( s ) );
Py_DECREF(s); Py_DECREF(s);
} }
@ -348,7 +351,7 @@ py( PDEBUG_CLIENT4 client, PCSTR args)
} }
else else
{ {
DbgPrint::dprintln( "script file not found" ); dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "script file not found\n" );
} }
} }
@ -391,8 +394,8 @@ pycmd( PDEBUG_CLIENT4 client, PCSTR args )
{ {
PyObject *s = PyObject_Str(errvalue); PyObject *s = PyObject_Str(errvalue);
DbgPrint::dprintln( PyString_AS_STRING( s ) ); dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "%s\n", PyString_AS_STRING( s ) );
Py_DECREF(s); Py_DECREF(s);
} }
@ -442,8 +445,8 @@ pycmd( PDEBUG_CLIENT4 client, PCSTR args )
{ {
PyObject *s = PyObject_Str(errvalue); PyObject *s = PyObject_Str(errvalue);
DbgPrint::dprintln( PyString_AS_STRING( s ) ); dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "%s/n", PyString_AS_STRING( s ) );
Py_DECREF(s); Py_DECREF(s);
} }

View File

@ -9,6 +9,7 @@ struct DbgExt {
IDebugClient4 *client4; IDebugClient4 *client4;
IDebugControl *control; IDebugControl *control;
IDebugControl4 *control4;
IDebugRegisters *registers; IDebugRegisters *registers;

View File

@ -1,6 +1,8 @@
#pragma once #pragma once
#include "dbgprint.h" #include "dbgprint.h"
#include <boost/python.hpp>
#include <boost/python/object.hpp>
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
@ -9,12 +11,9 @@ class dbgOut {
public: public:
void void
write( const std::string& str ) { write( const boost::python::object &str ) {
DbgPrint::dprint( str ); DbgPrint::dprint( str );
} }
private:
}; };
@ -36,9 +35,6 @@ public:
return std::string( str ); return std::string( str );
} }
private:
}; };

View File

@ -7,16 +7,18 @@
using namespace std; using namespace std;
void DbgPrint::dprint( const string& str ) void DbgPrint::dprint( const boost::python::object& obj, bool dml )
{ {
HRESULT hres = dbgExt->control->ControlledOutput( DEBUG_OUTCTL_AMBIENT_DML, DEBUG_OUTPUT_NORMAL, str.c_str() ); std::wstring str = boost::python::extract<std::wstring>( obj );
if ( FAILED( hres ) )
std::cout << str; dbgExt->control4->ControlledOutputWide( dml ? DEBUG_OUTCTL_AMBIENT_DML : DEBUG_OUTCTL_AMBIENT_TEXT, DEBUG_OUTPUT_NORMAL, str.c_str() );
} }
void DbgPrint::dprintln( const std::string& str ) void DbgPrint::dprintln( const boost::python::object& obj, bool dml )
{ {
DbgPrint::dprint( str ); std::wstring str = boost::python::extract<std::wstring>( obj );
DbgPrint::dprint( "\r\n" ); str += L"\r\n";
dbgExt->control4->ControlledOutputWide( dml ? DEBUG_OUTCTL_AMBIENT_DML : DEBUG_OUTCTL_AMBIENT_TEXT, DEBUG_OUTPUT_NORMAL, str.c_str() );
} }

View File

@ -3,14 +3,17 @@
#pragma once #pragma once
#include <string> #include <string>
#include <boost/python.hpp>
#include <boost/python/object.hpp>
class DbgPrint { class DbgPrint {
public: public:
static void dprint( const std::string& str ); static void dprint( const boost::python::object& obj, bool dml = false );
static void dprintln( const std::string& str ); static void dprintln( const boost::python::object& obj, bool dml = false );
}; };