From 8cab8ae27decfe37a1c3ec68853517ba22ec443a Mon Sep 17 00:00:00 2001 From: "SND\\kernelnet_cp" Date: Wed, 26 Jan 2011 16:17:33 +0000 Subject: [PATCH] [!] 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 --- pykd/dbgext.cpp | 21 ++++++++++++--------- pykd/dbgext.h | 1 + pykd/dbginput.h | 12 ++++-------- pykd/dbgprint.cpp | 16 +++++++++------- pykd/dbgprint.h | 9 ++++++--- 5 files changed, 32 insertions(+), 27 deletions(-) diff --git a/pykd/dbgext.cpp b/pykd/dbgext.cpp index ab43e66..478701d 100644 --- a/pykd/dbgext.cpp +++ b/pykd/dbgext.cpp @@ -71,6 +71,8 @@ private: 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, 2, 3 ) BOOST_PYTHON_FUNCTION_OVERLOADS( loadWords, loadArray, 2, 3 ) @@ -92,8 +94,8 @@ BOOST_PYTHON_MODULE( pykd ) boost::python::def( "createSession", &dbgCreateSession ); boost::python::def( "isSessionStart", &dbgIsSessionStart ); boost::python::def( "symbolsPath", &dbgSymPath ); - boost::python::def( "dprint", &DbgPrint::dprint ); - boost::python::def( "dprintln", &DbgPrint::dprintln ); + boost::python::def( "dprint", &DbgPrint::dprint, dprint( boost::python::args( "str", "dml" ), "" ) ); + boost::python::def( "dprintln", &DbgPrint::dprintln, dprintln( boost::python::args( "str", "dml" ), "" ) ); boost::python::def( "loadDump", &dbgLoadDump ); boost::python::def( "dbgCommand", &dbgCommand ); boost::python::def( "is64bitSystem", &is64bitSystem ); @@ -110,7 +112,7 @@ BOOST_PYTHON_MODULE( pykd ) boost::python::def( "getOffset", &findAddressForSymbol ); boost::python::def( "findModule", &findModule ); boost::python::def( "addr64", &addr64 ); - boost::python::def( "loadBytes", loadArray, loadBytes( boost::python::args( "address", "number", "phyAddr" ), "" ) ); + boost::python::def( "loadBytes", &loadArray, loadBytes( boost::python::args( "address", "number", "phyAddr" ), "" ) ); boost::python::def( "loadWords", &loadArray, loadWords( boost::python::args( "address", "number", "phyAddr" ), "" ) ); boost::python::def( "loadDWords", &loadArray, loadDWords( boost::python::args( "address", "number", "phyAddr" ), "" ) ); boost::python::def( "loadQWords", &loadArray, 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(IDebugControl4), (void **)&dbgExt->control4 ); client->QueryInterface( __uuidof(IDebugRegisters), (void **)&dbgExt->registers ); @@ -331,7 +334,7 @@ py( PDEBUG_CLIENT4 client, PCSTR args) { 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); } @@ -348,7 +351,7 @@ py( PDEBUG_CLIENT4 client, PCSTR args) } 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); - DbgPrint::dprintln( PyString_AS_STRING( s ) ); - + dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "%s\n", PyString_AS_STRING( s ) ); + Py_DECREF(s); } @@ -442,8 +445,8 @@ pycmd( PDEBUG_CLIENT4 client, PCSTR args ) { 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); } diff --git a/pykd/dbgext.h b/pykd/dbgext.h index ff4d043..3dc4c5d 100644 --- a/pykd/dbgext.h +++ b/pykd/dbgext.h @@ -9,6 +9,7 @@ struct DbgExt { IDebugClient4 *client4; IDebugControl *control; + IDebugControl4 *control4; IDebugRegisters *registers; diff --git a/pykd/dbginput.h b/pykd/dbginput.h index d23ce44..a1a67f7 100644 --- a/pykd/dbginput.h +++ b/pykd/dbginput.h @@ -1,6 +1,8 @@ #pragma once #include "dbgprint.h" +#include +#include ///////////////////////////////////////////////////////////////////////////////// @@ -9,12 +11,9 @@ class dbgOut { public: void - write( const std::string& str ) { + write( const boost::python::object &str ) { DbgPrint::dprint( str ); - } - -private: - + } }; @@ -36,9 +35,6 @@ public: return std::string( str ); } - -private: - }; diff --git a/pykd/dbgprint.cpp b/pykd/dbgprint.cpp index d4a7b15..b0089c7 100644 --- a/pykd/dbgprint.cpp +++ b/pykd/dbgprint.cpp @@ -7,16 +7,18 @@ 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() ); - if ( FAILED( hres ) ) - std::cout << str; + std::wstring str = boost::python::extract( obj ); + + 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 ); - DbgPrint::dprint( "\r\n" ); + std::wstring str = boost::python::extract( obj ); + str += L"\r\n"; + + dbgExt->control4->ControlledOutputWide( dml ? DEBUG_OUTCTL_AMBIENT_DML : DEBUG_OUTCTL_AMBIENT_TEXT, DEBUG_OUTPUT_NORMAL, str.c_str() ); } diff --git a/pykd/dbgprint.h b/pykd/dbgprint.h index c64d754..0f133c7 100644 --- a/pykd/dbgprint.h +++ b/pykd/dbgprint.h @@ -3,14 +3,17 @@ #pragma once #include +#include +#include class DbgPrint { public: - static void dprint( const std::string& str ); - - static void dprintln( const std::string& str ); + static void dprint( const boost::python::object& obj, bool dml = false ); + + static void dprintln( const boost::python::object& obj, bool dml = false ); + };