[0.2.x] added : windbg commands

git-svn-id: https://pykd.svn.codeplex.com/svn@78848 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\kernelnet_cp 2012-08-14 10:53:05 +00:00 committed by Mikhail I. Izmestev
parent c2f9cdea67
commit b06fe5b226
12 changed files with 240 additions and 570 deletions

View File

@ -17,6 +17,13 @@ bool isKernelDebugging();
void debugGo(); void debugGo();
// debug output
void dprint( const std::wstring &str, bool dml = false );
void dprintln( const std::wstring &str, bool dml = false );
std::string dreadline();
void eprint( const std::wstring &str );
void eprintln( const std::wstring &str );
// system properties // system properties
ULONG ptrSize(); ULONG ptrSize();
bool is64bitSystem(); bool is64bitSystem();
@ -48,5 +55,6 @@ struct STACK_FRAME_DESC {
ULONG getStackTraceFrameCount(); ULONG getStackTraceFrameCount();
void getStackTrace( STACK_FRAME_DESC* frames, ULONG frameCount, ULONG* frameReturned = NULL ); void getStackTrace( STACK_FRAME_DESC* frames, ULONG frameCount, ULONG* frameReturned = NULL );
}; };

View File

@ -3,13 +3,50 @@
#include <dbgeng.h> #include <dbgeng.h>
//#include <boost/tokenizer.hpp> #include "win/dbgio.h"
// #include "win/dbgeng.h"
//#include "windbg.h" #include "win/dbgpath.h"
//#include "dbgclient.h" #include "win/windbg.h"
//#include "dbgpath.h"
//using namespace pykd; using namespace pykd;
////////////////////////////////////////////////////////////////////////////////
extern "C" void initpykd();
////////////////////////////////////////////////////////////////////////////////
WindbgGlobalSession::WindbgGlobalSession()
{
PyImport_AppendInittab("pykd", initpykd );
PyEval_InitThreads();
Py_Initialize();
main = boost::python::import("__main__");
python::object main_namespace = main.attr("__dict__");
// äåëàåì àíàëîã from pykd import *
python::object pykd = boost::python::import( "pykd" );
python::dict pykd_namespace( pykd.attr("__dict__") );
python::list iterkeys( pykd_namespace.iterkeys() );
for (int i = 0; i < boost::python::len(iterkeys); i++)
{
std::string key = boost::python::extract<std::string>(iterkeys[i]);
main_namespace[ key ] = pykd_namespace[ key ];
}
pyState = PyEval_SaveThread();
}
volatile LONG WindbgGlobalSession::sessionCount = 0;
WindbgGlobalSession *WindbgGlobalSession::windbgGlobalSession = NULL;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -43,7 +80,7 @@ DebugExtensionInitialize(
*Version = DEBUG_EXTENSION_VERSION( 1, 0 ); *Version = DEBUG_EXTENSION_VERSION( 1, 0 );
*Flags = 0; *Flags = 0;
// WindbgGlobalSession::StartWindbgSession(); WindbgGlobalSession::StartWindbgSession();
return S_OK; return S_OK;
} }
@ -54,7 +91,7 @@ VOID
CALLBACK CALLBACK
DebugExtensionUninitialize() DebugExtensionUninitialize()
{ {
// WindbgGlobalSession::StopWindbgSession(); WindbgGlobalSession::StopWindbgSession();
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -63,6 +100,109 @@ HRESULT
CALLBACK CALLBACK
py( PDEBUG_CLIENT4 client, PCSTR args ) py( PDEBUG_CLIENT4 client, PCSTR args )
{ {
g_dbgEng.setClient( client );
WindbgGlobalSession::RestorePyState();
PyThreadState *globalInterpreter = PyThreadState_Swap( NULL );
PyThreadState *localInterpreter = Py_NewInterpreter();
try {
// ïîëó÷àåì äîñòïó ê ãëîáàëüíîìó ìàïó ( íóæåí äëÿ âûçîâà exec_file )
python::object main = python::import("__main__");
python::object global(main.attr("__dict__"));
// íàñòðàèâàåì ââîä/âûâîä ( ÷òîáû â ñêðèïòå ìîæíî áûëî ïèñàòü print )
python::object sys = python::import("sys");
sys.attr("stdout") = python::object( DbgOut() );
sys.attr("stderr") = python::object( DbgErr() );
sys.attr("stdin") = python::object( DbgIn() );
// èìïîðòèðóåì ìîäóëü îáðàáîòêè èñêëþ÷åíèé ( íóæåí äëÿ âûâîäà traceback à )
python::object tracebackModule = python::import("traceback");
// ðàçáîð ïàðàìåòðîâ
typedef boost::escaped_list_separator<char> char_separator_t;
typedef boost::tokenizer< char_separator_t > char_tokenizer_t;
std::string argsStr( args );
char_tokenizer_t token( argsStr , char_separator_t( "", " \t", "\"" ) );
std::vector<std::string> argsList;
for ( char_tokenizer_t::iterator it = token.begin(); it != token.end(); ++it )
{
if ( *it != "" )
argsList.push_back( *it );
}
if ( argsList.size() == 0 )
return S_OK;
char **pythonArgs = new char* [ argsList.size() ];
for ( size_t i = 0; i < argsList.size(); ++i )
pythonArgs[i] = const_cast<char*>( argsList[i].c_str() );
PySys_SetArgv( (int)argsList.size(), pythonArgs );
delete[] pythonArgs;
// íàéòè ïóòü ê ôàéëó
std::string fullScriptName;
DbgPythonPath dbgPythonPath;
if ( !dbgPythonPath.getFullFileName( argsList[0], fullScriptName ) )
{
eprintln( L"script file not found" );
}
else
try {
python::object result;
result = python::exec_file( fullScriptName.c_str(), global, global );
}
catch( boost::python::error_already_set const & )
{
// îøèáêà â ñêðèïòå
PyObject *errtype = NULL, *errvalue = NULL, *traceback = NULL;
PyErr_Fetch( &errtype, &errvalue, &traceback );
PyErr_NormalizeException( &errtype, &errvalue, &traceback );
std::wstringstream sstr;
python::object lst =
python::object( tracebackModule.attr("format_exception" ) )(
python::handle<>( errtype ),
python::handle<>( python::allow_null( errvalue ) ),
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;
eprintln( sstr.str() );
}
}
catch(...)
{
eprintln( L"unexpected error" );
}
Py_EndInterpreter( localInterpreter );
PyThreadState_Swap( globalInterpreter );
WindbgGlobalSession::SavePyState();
return S_OK; return S_OK;
} }
@ -72,248 +212,38 @@ HRESULT
CALLBACK CALLBACK
pycmd( PDEBUG_CLIENT4 client, PCSTR args ) pycmd( PDEBUG_CLIENT4 client, PCSTR args )
{ {
g_dbgEng.setClient( client );
WindbgGlobalSession::RestorePyState();
try {
// ïåðåíàïðàâëåíèå ñòàíäàðòíûõ ïîòîêîâ ÂÂ
python::object sys = python::import("sys");
sys.attr("stdout") = python::object( DbgOut() );
sys.attr("stderr") = python::object( DbgErr() );
sys.attr("stdin") = python::object( DbgIn() );
PyRun_String(
"__import__('code').InteractiveConsole(__import__('__main__').__dict__).interact()",
Py_file_input,
WindbgGlobalSession::global().ptr(),
WindbgGlobalSession::global().ptr()
);
// âûõîä èç èíòåðïðåòàòîðà ïðîèñõîäèò ÷åðåç èñêëþ÷åíèå raise SystemExit(code)
// êîòîðîå ïîòîì ìîæåò ïîìåøàòü èñïîëíåíèþ callback îâ
PyErr_Clear();
}
catch(...)
{
eprintln( L"unexpected error" );
}
WindbgGlobalSession::SavePyState();
return S_OK; return S_OK;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//
//extern "C" void initpykd();
//
//////////////////////////////////////////////////////////////////////////////////
//
//WindbgGlobalSession::WindbgGlobalSession() {
//
// PyImport_AppendInittab("pykd", initpykd );
//
// PyEval_InitThreads();
//
// Py_Initialize();
//
// main = boost::python::import("__main__");
//
// python::object main_namespace = main.attr("__dict__");
//
// // äåëàåì àíàëîã from pykd import *
// python::object pykd = boost::python::import( "pykd" );
//
// python::dict pykd_namespace( pykd.attr("__dict__") );
//
// python::list iterkeys( pykd_namespace.iterkeys() );
//
// for (int i = 0; i < boost::python::len(iterkeys); i++)
// {
// std::string key = boost::python::extract<std::string>(iterkeys[i]);
//
// main_namespace[ key ] = pykd_namespace[ key ];
// }
//
// pyState = PyEval_SaveThread();
//}
//
//
//volatile LONG WindbgGlobalSession::sessionCount = 0;
//
//WindbgGlobalSession *WindbgGlobalSession::windbgGlobalSession = NULL;
//
///////////////////////////////////////////////////////////////////////////////////
//
//HRESULT
//CALLBACK
//DebugExtensionInitialize(
// OUT PULONG Version,
// OUT PULONG Flags )
//{
// *Version = DEBUG_EXTENSION_VERSION( 1, 0 );
// *Flags = 0;
//
// WindbgGlobalSession::StartWindbgSession();
//
// return S_OK;
//}
//
//////////////////////////////////////////////////////////////////////////////////
//
//VOID
//CALLBACK
//DebugExtensionUninitialize()
//{
// WindbgGlobalSession::StopWindbgSession();
//}
//
//////////////////////////////////////////////////////////////////////////////////
//
//HRESULT
//CALLBACK
//py( PDEBUG_CLIENT4 client, PCSTR args )
//{
// DebugClientPtr dbgClient = DebugClient::createDbgClient( client );
// DebugClientPtr oldClient = DebugClient::setDbgClientCurrent( dbgClient );
//
// WindbgGlobalSession::RestorePyState();
//
// PyThreadState *globalInterpreter = PyThreadState_Swap( NULL );
// PyThreadState *localInterpreter = Py_NewInterpreter();
//
// try {
//
// // ïîëó÷àåì äîñòïó ê ãëîáàëüíîìó ìàïó ( íóæåí äëÿ âûçîâà exec_file )
// python::object main = python::import("__main__");
//
// python::object global(main.attr("__dict__"));
//
// // íàñòðàèâàåì ââîä/âûâîä ( ÷òîáû â ñêðèïòå ìîæíî áûëî ïèñàòü print )
//
// python::object sys = python::import("sys");
//
// sys.attr("stdout") = python::object( dbgClient->dout() );
// sys.attr("stderr") = python::object( dbgClient->dout() );
// sys.attr("stdin") = python::object( dbgClient->din() );
//
// // èìïîðòèðóåì ìîäóëü îáðàáîòêè èñêëþ÷åíèé ( íóæåí äëÿ âûâîäà traceback à )
// python::object tracebackModule = python::import("traceback");
//
// // ðàçáîð ïàðàìåòðîâ
// typedef boost::escaped_list_separator<char> char_separator_t;
// typedef boost::tokenizer< char_separator_t > char_tokenizer_t;
//
// std::string argsStr( args );
//
// char_tokenizer_t token( argsStr , char_separator_t( "", " \t", "\"" ) );
// std::vector<std::string> argsList;
//
// for ( char_tokenizer_t::iterator it = token.begin(); it != token.end(); ++it )
// {
// if ( *it != "" )
// argsList.push_back( *it );
// }
//
// if ( argsList.size() == 0 )
// return S_OK;
//
// char **pythonArgs = new char* [ argsList.size() ];
//
// for ( size_t i = 0; i < argsList.size(); ++i )
// pythonArgs[i] = const_cast<char*>( argsList[i].c_str() );
//
// PySys_SetArgv( (int)argsList.size(), pythonArgs );
//
// delete[] pythonArgs;
//
// // íàéòè ïóòü ê ôàéëó
// std::string fullScriptName;
// DbgPythonPath dbgPythonPath;
//
// if ( !dbgPythonPath.getFullFileName( argsList[0], fullScriptName ) )
// {
// dbgClient->eprintln( L"script file not found" );
// }
// else
// try {
//
// python::object result;
//
// result = python::exec_file( fullScriptName.c_str(), global, global );
// }
// catch( boost::python::error_already_set const & )
// {
// // îøèáêà â ñêðèïòå
// PyObject *errtype = NULL, *errvalue = NULL, *traceback = NULL;
//
// PyErr_Fetch( &errtype, &errvalue, &traceback );
//
// PyErr_NormalizeException( &errtype, &errvalue, &traceback );
//
// std::wstringstream sstr;
//
// python::object lst =
// python::object( tracebackModule.attr("format_exception" ) )(
// python::handle<>( errtype ),
// python::handle<>( python::allow_null( errvalue ) ),
// 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() );
// }
//
// }
// catch(...)
// {
// dbgClient->eprintln( L"unexpected error" );
// }
//
// Py_EndInterpreter( localInterpreter );
// PyThreadState_Swap( globalInterpreter );
//
// WindbgGlobalSession::SavePyState();
//
// DebugClient::setDbgClientCurrent( oldClient );
//
// return S_OK;
//}
//
//////////////////////////////////////////////////////////////////////////////////
//
//HRESULT
//CALLBACK
//pycmd( PDEBUG_CLIENT4 client, PCSTR args )
//{
// if ( g_dbgClient->client() != client )
// {
// DebugClientPtr dbgClient = DebugClient::createDbgClient( client );
// DebugClient::setDbgClientCurrent( dbgClient );
// }
//
// WindbgGlobalSession::RestorePyState();
//
// ULONG mask = 0;
// client->GetOutputMask( &mask );
//
// try {
//
// // ïåðåíàïðàâëåíèå ñòàíäàðòíûõ ïîòîêîâ ÂÂ
// python::object sys = python::import("sys");
//
// sys.attr("stdout") = python::object( DbgOut( client ) );
// sys.attr("stderr") = python::object( DbgOut( client ) );
// sys.attr("stdin") = python::object( DbgIn( client ) );
//
// client->SetOutputMask( DEBUG_OUTPUT_NORMAL );
//
// PyRun_String(
// "__import__('code').InteractiveConsole(__import__('__main__').__dict__).interact()",
// Py_file_input,
// WindbgGlobalSession::global().ptr(),
// WindbgGlobalSession::global().ptr()
// );
//
// // âûõîä èç èíòåðïðåòàòîðà ïðîèñõîäèò ÷åðåç èñêëþ÷åíèå raise SystemExit(code)
// // êîòîðîå ïîòîì ìîæåò ïîìåøàòü èñïîëíåíèþ callback îâ
// PyErr_Clear();
// }
// catch(...)
// {
// //dbgClient->eprintln( L"unexpected error" );
// }
//
// client->SetOutputMask( mask );
//
// WindbgGlobalSession::SavePyState();
//
// return S_OK;
//}
//
//////////////////////////////////////////////////////////////////////////////////

View File

@ -1,129 +0,0 @@
#include "stdafx.h"
#include <iostream>
#include "dbgio.h"
#include "dbgclient.h"
#include "windbg.h"
namespace pykd {
///////////////////////////////////////////////////////////////////////////////////
void DebugClient::dprint( const std::wstring &str, bool dml )
{
if ( WindbgGlobalSession::isInit() )
{
for ( size_t i = 0; i < str.size() / 100 + 1; ++i )
{
m_control->ControlledOutputWide(
dml ? DEBUG_OUTCTL_AMBIENT_DML : DEBUG_OUTCTL_AMBIENT_TEXT, DEBUG_OUTPUT_NORMAL,
L"%ws",
str.substr( i*100, min( str.size() - i*100, 100 ) ).c_str()
);
}
}
else
{
python::object sys = python::import("sys");
sys.attr("stdout").attr("write")( str );
}
}
void dprint( const std::wstring &str, bool dml )
{
g_dbgClient->dprint( str, dml );
}
///////////////////////////////////////////////////////////////////////////////////
void DebugClient::dprintln( const std::wstring &str, bool dml )
{
this->dprint( str + L"\r\n", dml );
}
void dprintln( const std::wstring &str, bool dml )
{
g_dbgClient->dprintln( str, dml );
}
///////////////////////////////////////////////////////////////////////////////////
void DebugClient::eprint( const std::wstring &str )
{
if ( WindbgGlobalSession::isInit() )
{
for ( size_t i = 0; i < str.size() / 100 + 1; ++i )
{
m_control->OutputWide(
DEBUG_OUTPUT_ERROR,
L"%ws",
str.substr( i*100, min( str.size() - i*100, 100 ) ).c_str()
);
}
}
else
{
python::object sys = python::import("sys");
sys.attr("stderr").attr("write")( str );
}
}
void eprint( const std::wstring &str )
{
g_dbgClient->eprint( str );
}
///////////////////////////////////////////////////////////////////////////////////
void DebugClient::eprintln( const std::wstring &str )
{
this->eprint( str + L"\r\n");
}
void eprintln( const std::wstring &str )
{
g_dbgClient->eprintln( str );
}
///////////////////////////////////////////////////////////////////////////////////
void
DbgOut::write( const std::wstring &str )
{
if ( WindbgGlobalSession::isInit() )
{
for ( size_t i = 0; i < str.size() / 100 + 1; ++i )
{
m_control->ControlledOutputWide(
DEBUG_OUTCTL_AMBIENT_TEXT,
DEBUG_OUTPUT_NORMAL,
L"%ws",
str.substr( i*100, min( str.size() - i*100, 100 ) ).c_str()
);
}
}
else
{
python::object sys = python::import("sys");
sys.attr("stderr").attr("write")( str );
}
}
///////////////////////////////////////////////////////////////////////////////////
std::string
DbgIn::readline()
{
char str[0x100];
ULONG inputSize = 0;
m_control->Input( str, sizeof(str), &inputSize );
return std::string( str ) + "\n";
}
///////////////////////////////////////////////////////////////////////////////////
}; // namesapce pykd

View File

@ -1,183 +0,0 @@
#pragma once
#include "dbgobj.h"
#include <vector>
namespace pykd {
///////////////////////////////////////////////////////////////////////////////////
void dprint( const std::wstring &str, bool dml = false );
void dprintln( const std::wstring &str, bool dml = false );
void eprint( const std::wstring &str );
void eprintln( const std::wstring &str );
/////////////////////////////////////////////////////////////////////////////////
class DbgOut : private DbgObject {
public:
DbgOut( IDebugClient4 *client ) : DbgObject( client )
{}
void
write( const std::wstring &str );
};
/////////////////////////////////////////////////////////////////////////////////
class DbgIn : private DbgObject {
public:
DbgIn( IDebugClient4 *client ) : DbgObject( client )
{}
std::string
readline();
};
/////////////////////////////////////////////////////////////////////////////////
// êëàññ äëÿ ïåðåõâàòà âûâîäà â îòëàä÷èê
class OutputReader : private DbgObject, public IDebugOutputCallbacks, private boost::noncopyable {
public:
explicit OutputReader( IDebugClient4 *client ) : DbgObject( client )
{
HRESULT hres;
hres = m_client->GetOutputCallbacks( &m_previousCallback );
if ( FAILED( hres ) )
throw DbgException( "IDebugClient::GetOutputCallbacks failed" );
hres = m_client->SetOutputCallbacks( this );
if ( FAILED( hres ) )
throw DbgException( "IDebugClient::GetOutputCallbacks failed" );
}
~OutputReader()
{
m_client->SetOutputCallbacks( m_previousCallback );
}
const std::string&
Line() const {
return m_readLine;
}
private:
// IUnknown.
STDMETHOD(QueryInterface)(
__in REFIID InterfaceId,
__out PVOID* Interface ) {
return E_NOINTERFACE;
}
STDMETHOD_(ULONG, AddRef)() {
return 1L;
}
STDMETHOD_(ULONG, Release)() {
return 0L;
}
STDMETHOD(Output)(
__in ULONG Mask,
__in PCSTR Text )
{
if ( Mask == DEBUG_OUTPUT_NORMAL )
{
m_readLine += std::string( Text );
}
return S_OK;
}
private:
std::string m_readLine;
CComPtr<IDebugOutputCallbacks> m_previousCallback;
};
///////////////////////////////////////////////////////////////////////////////////
//
//class InputReader : public IDebugInputCallbacks, private DbgObject, private boost::noncopyable {
//
//public:
//
// explicit InputReader( IDebugClient4 *debugClient ) : DbgObject( debugClient )
// {
// HRESULT hres;
//
// hres = m_client->GetInputCallbacks( &m_previousCallback );
// if ( FAILED( hres ) )
// throw DbgException( "IDebugClient::GetInputCallbacks failed" );
//
// hres = m_client->SetInputCallbacks( this );
// if ( FAILED( hres ) )
// throw DbgException( "IDebugClient::SetInputCallbacks failed" );
// }
//
// ~InputReader()
// {
// if ( m_previousCallback )
// m_client->SetInputCallbacks( m_previousCallback );
// }
//
//
//private:
//
// // IUnknown.
// STDMETHOD(QueryInterface)(
// __in REFIID InterfaceId,
// __out PVOID* Interface ) {
// return E_NOINTERFACE;
// }
//
// STDMETHOD_(ULONG, AddRef)() {
// return 1L;
// }
//
//
// STDMETHOD_(ULONG, Release)() {
// return 0L;
// }
//
// STDMETHOD( EndInput )() {
// return S_OK;
// }
//
// STDMETHOD( StartInput )(
// IN ULONG BufferSize ) {
//
// std::vector<char> buf(BufferSize);
//
// ULONG inputSize;
//
// m_control->Input( &buf[0], BufferSize, &inputSize );
//
// m_control->ReturnInput( &buf[0] );
//
// return S_OK;
// }
//
//private:
//
// CComPtr<IDebugInputCallbacks> m_previousCallback;
//
//};
/////////////////////////////////////////////////////////////////////////////////
};

View File

@ -365,6 +365,10 @@
RelativePath=".\dbgmem.cpp" RelativePath=".\dbgmem.cpp"
> >
</File> </File>
<File
RelativePath=".\win\dbgpath.cpp"
>
</File>
<File <File
RelativePath=".\disasm.cpp" RelativePath=".\disasm.cpp"
> >
@ -463,6 +467,10 @@
RelativePath=".\dbgmem.h" RelativePath=".\dbgmem.h"
> >
</File> </File>
<File
RelativePath=".\win\dbgpath.h"
>
</File>
<File <File
RelativePath=".\disasm.h" RelativePath=".\disasm.h"
> >
@ -545,6 +553,14 @@
RelativePath=".\win\dbgeng.h" RelativePath=".\win\dbgeng.h"
> >
</File> </File>
<File
RelativePath=".\win\dbgio.cpp"
>
</File>
<File
RelativePath=".\win\dbgio.h"
>
</File>
<File <File
RelativePath=".\win\memory.cpp" RelativePath=".\win\memory.cpp"
> >
@ -553,6 +569,10 @@
RelativePath=".\win\utils.h" RelativePath=".\win\utils.h"
> >
</File> </File>
<File
RelativePath=".\win\windbg.h"
>
</File>
</Filter> </Filter>
<Filter <Filter
Name="dia" Name="dia"

View File

@ -20,6 +20,8 @@
#include "stkframe.h" #include "stkframe.h"
#include "localvar.h" #include "localvar.h"
#include "win/dbgio.h"
using namespace pykd; using namespace pykd;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -33,6 +35,10 @@ static const std::string pykdVersion = PYKD_VERSION_BUILD_STR
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
BOOST_PYTHON_FUNCTION_OVERLOADS( dprint_, dprint, 1, 2 );
BOOST_PYTHON_FUNCTION_OVERLOADS( dprintln_, dprintln, 1, 2 );
BOOST_PYTHON_FUNCTION_OVERLOADS( loadChars_, loadChars, 2, 3 ); BOOST_PYTHON_FUNCTION_OVERLOADS( loadChars_, loadChars, 2, 3 );
BOOST_PYTHON_FUNCTION_OVERLOADS( loadWChars_, loadWChars, 2, 3 ); BOOST_PYTHON_FUNCTION_OVERLOADS( loadWChars_, loadWChars, 2, 3 );
BOOST_PYTHON_FUNCTION_OVERLOADS( loadBytes_, loadBytes, 2, 3 ); BOOST_PYTHON_FUNCTION_OVERLOADS( loadBytes_, loadBytes, 2, 3 );
@ -67,6 +73,20 @@ BOOST_PYTHON_MODULE( pykd )
python::def( "go", &debugGo, python::def( "go", &debugGo,
"Go debugging" ); "Go debugging" );
// Debug output
python::def( "dprint", &pykd::dprint, dprint_( boost::python::args( "str", "dml" ),
"Print out string. If dml = True string is printed with dml highlighting ( only for windbg )" ) );
python::def( "dprintln", &pykd::dprintln, dprintln_( boost::python::args( "str", "dml" ),
"Print out string and insert end of line symbol. If dml = True string is printed with dml highlighting ( only for windbg )" ) );
// Python debug output console helper classes
python::class_<DbgOut>( "dout", "dout", python::no_init )
.def( "write", &DbgOut::write );
python::class_<DbgErr>( "dout", "dout", python::no_init )
.def( "write", &DbgErr::write );
python::class_<DbgIn>( "din", "din", python::no_init )
.def( "readline", &DbgIn::readline );
// system properties // system properties
python::def( "ptrSize", &ptrSize, python::def( "ptrSize", &ptrSize,
"Return effective pointer size" ); "Return effective pointer size" );

View File

@ -59,3 +59,4 @@ namespace python = boost::python;
#include <boost/regex.hpp> #include <boost/regex.hpp>
#include <boost/variant.hpp> #include <boost/variant.hpp>
#include <boost/tokenizer.hpp>

View File

@ -104,7 +104,6 @@ void loadDump( const std::wstring &fileName )
hres = g_dbgEng->control->WaitForEvent(DEBUG_WAIT_DEFAULT, INFINITE); hres = g_dbgEng->control->WaitForEvent(DEBUG_WAIT_DEFAULT, INFINITE);
if ( FAILED( hres ) ) if ( FAILED( hres ) )
throw DbgException( "IDebugControl::WaitForEvent failed" ); throw DbgException( "IDebugControl::WaitForEvent failed" );
} }
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
@ -169,7 +168,8 @@ void debugGo()
} while( currentStatus != DEBUG_STATUS_BREAK && currentStatus != DEBUG_STATUS_NO_DEBUGGEE ); } while( currentStatus != DEBUG_STATUS_BREAK && currentStatus != DEBUG_STATUS_NO_DEBUGGEE );
} }
///////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
ULONG64 findModuleBase( const std::string &moduleName ) ULONG64 findModuleBase( const std::string &moduleName )
{ {

View File

@ -56,6 +56,11 @@ public:
return m_bind.get(); return m_bind.get();
} }
void setClient( PDEBUG_CLIENT4 client )
{
m_bind.reset(new DbgEngBind(client) );
}
private: private:
std::auto_ptr<DbgEngBind> m_bind; std::auto_ptr<DbgEngBind> m_bind;
@ -66,6 +71,6 @@ private:
extern DebugEngine g_dbgEng; extern DebugEngine g_dbgEng;
/////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
}; };

View File

@ -1,6 +1,5 @@
#pragma once #pragma once
namespace pykd { namespace pykd {
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
@ -72,5 +71,4 @@ private:
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
}; // namespace pykd }; // namespace pykd