mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-19 19:13:22 +08:00
[0.2.x] fixed : dbgCommand return unicode string
git-svn-id: https://pykd.svn.codeplex.com/svn@85813 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
parent
fd89d45dfe
commit
cf6eea3f78
@ -23,13 +23,13 @@ void debugGo();
|
||||
void debugStep();
|
||||
void debugStepIn();
|
||||
void debugBreak();
|
||||
std::string debugCommand( const std::wstring &command );
|
||||
std::wstring debugCommand( const std::wstring &command );
|
||||
BaseTypeVariant evaluate( const std::wstring &expression, bool cplusplus = false );
|
||||
|
||||
// debug output
|
||||
void dprint( const std::wstring &str, bool dml = false );
|
||||
void dprintln( const std::wstring &str, bool dml = false );
|
||||
std::string dreadline();
|
||||
std::wstring dreadline();
|
||||
void eprint( const std::wstring &str );
|
||||
void eprintln( const std::wstring &str );
|
||||
|
||||
@ -203,7 +203,7 @@ void appendSymbolPath(const std::string &symPath);
|
||||
// Extensions
|
||||
ULONG64 loadExtension(const std::wstring &extPath );
|
||||
void removeExtension( ULONG64 extHandle );
|
||||
std::string callExtension( ULONG64 extHandle, const std::wstring command, const std::wstring ¶ms );
|
||||
std::wstring callExtension( ULONG64 extHandle, const std::wstring command, const std::wstring ¶ms );
|
||||
|
||||
};
|
||||
|
||||
|
@ -265,7 +265,7 @@ BaseTypeVariant evaluate( const std::wstring &expression, bool cplusplus )
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::string debugCommand( const std::wstring &command )
|
||||
std::wstring debugCommand( const std::wstring &command )
|
||||
{
|
||||
PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate );
|
||||
|
||||
@ -275,9 +275,9 @@ std::string debugCommand( const std::wstring &command )
|
||||
hres = g_dbgEng->control->ExecuteWide( DEBUG_OUTCTL_THIS_CLIENT, command.c_str(), 0 );
|
||||
|
||||
if ( FAILED( hres ) )
|
||||
throw DbgException( "IDebugControl::Execute failed" );
|
||||
throw DbgException( "IDebugControl::ExecuteWide failed" );
|
||||
|
||||
return std::string( outReader.Line() );
|
||||
return outReader.Line();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@ -1314,7 +1314,7 @@ void removeExtension( ULONG64 extHandle )
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::string callExtension( ULONG64 extHandle, const std::wstring command, const std::wstring ¶ms )
|
||||
std::wstring callExtension( ULONG64 extHandle, const std::wstring command, const std::wstring ¶ms )
|
||||
{
|
||||
PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate );
|
||||
|
||||
@ -1327,7 +1327,7 @@ std::string callExtension( ULONG64 extHandle, const std::wstring command, const
|
||||
if ( FAILED( hres ) )
|
||||
throw DbgException( "IDebugControl::CallExtension failed" );
|
||||
|
||||
return std::string( outReader.Line() );
|
||||
return std::wstring( outReader.Line() );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -67,16 +67,16 @@ void eprintln( const std::wstring &str )
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::string dreadline()
|
||||
std::wstring dreadline()
|
||||
{
|
||||
PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate );
|
||||
|
||||
char str[0x100];
|
||||
wchar_t str[0x100];
|
||||
ULONG inputSize = 0;
|
||||
|
||||
g_dbgEng->control->Input( str, sizeof(str), &inputSize );
|
||||
g_dbgEng->control->InputWide( str, sizeof(str), &inputSize );
|
||||
|
||||
return std::string( str ) + "\n";
|
||||
return std::wstring( str ) + L"\n";
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -54,7 +54,7 @@ class DbgIn {
|
||||
|
||||
public:
|
||||
|
||||
std::string
|
||||
std::wstring
|
||||
readline() {
|
||||
return dreadline();
|
||||
}
|
||||
@ -68,7 +68,7 @@ public:
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class OutputReader : public IDebugOutputCallbacks, private boost::noncopyable {
|
||||
class OutputReader : public IDebugOutputCallbacksWide, private boost::noncopyable {
|
||||
|
||||
public:
|
||||
|
||||
@ -78,21 +78,21 @@ public:
|
||||
|
||||
m_client = client;
|
||||
|
||||
hres = m_client->GetOutputCallbacks( &m_previousCallback );
|
||||
hres = m_client->GetOutputCallbacksWide( &m_previousCallback );
|
||||
if ( FAILED( hres ) )
|
||||
throw DbgException( "IDebugClient::GetOutputCallbacks failed" );
|
||||
|
||||
hres = m_client->SetOutputCallbacks( this );
|
||||
hres = m_client->SetOutputCallbacksWide( this );
|
||||
if ( FAILED( hres ) )
|
||||
throw DbgException( "IDebugClient::GetOutputCallbacks failed" );
|
||||
}
|
||||
|
||||
~OutputReader()
|
||||
{
|
||||
m_client->SetOutputCallbacks( m_previousCallback );
|
||||
m_client->SetOutputCallbacksWide( m_previousCallback );
|
||||
}
|
||||
|
||||
const std::string&
|
||||
const std::wstring&
|
||||
Line() const {
|
||||
return m_readLine;
|
||||
}
|
||||
@ -117,22 +117,22 @@ private:
|
||||
|
||||
STDMETHOD(Output)(
|
||||
__in ULONG Mask,
|
||||
__in PCSTR Text )
|
||||
__in PCWSTR Text )
|
||||
{
|
||||
if ( Mask == DEBUG_OUTPUT_NORMAL )
|
||||
{
|
||||
m_readLine += std::string( Text );
|
||||
m_readLine += std::wstring( Text );
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
std::string m_readLine;
|
||||
std::wstring m_readLine;
|
||||
|
||||
CComPtr<IDebugOutputCallbacks> m_previousCallback;
|
||||
CComPtr<IDebugOutputCallbacksWide> m_previousCallback;
|
||||
|
||||
CComPtr<IDebugClient4> m_client;
|
||||
CComQIPtr<IDebugClient5> m_client;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -15,6 +15,8 @@ cfg.PromptManager.in_template = 'In <\\#>: '
|
||||
cfg.PromptManager.in2_template = ' .\\D.: '
|
||||
cfg.PromptManager.out_template = 'Out<\\#>: '
|
||||
|
||||
cfg.InteractiveShellApp.extensions = [ 'pykdmagic' ]
|
||||
|
||||
ipshell = InteractiveShellEmbed(config=cfg)
|
||||
|
||||
ipshell()
|
23
snippets/pykdmagic.py
Normal file
23
snippets/pykdmagic.py
Normal file
@ -0,0 +1,23 @@
|
||||
|
||||
from IPython.core.magic import Magics, magics_class, line_magic, cell_magic, line_cell_magic
|
||||
import pykd
|
||||
|
||||
@magics_class
|
||||
class PykdMagic (Magics):
|
||||
|
||||
@line_magic
|
||||
def kd(self,line):
|
||||
"any windbg command"
|
||||
try:
|
||||
pykd.dprintln( pykd.dbgCommand(line) )
|
||||
except pykd.BaseException:
|
||||
pykd.dprintln("invalid windbg syntax")
|
||||
return None
|
||||
|
||||
def load_ipython_extension(ipython):
|
||||
ipython.register_magics(PykdMagic)
|
||||
|
||||
def unload_ipython_extension(ipython):
|
||||
pass
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user