[pykd] added : callback for bp class ( breakpoint )

[pykd] changed:  refactored callbacks engine


git-svn-id: https://pykd.svn.codeplex.com/svn@63638 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\kernelnet_cp 2011-04-08 07:53:37 +00:00
parent a820ed3fdd
commit 60599dcfb6
14 changed files with 349 additions and 376 deletions

View File

@ -122,14 +122,32 @@ dbgExtensionClass::print() const
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
dbgBreakpointClass::breakpointMap dbgBreakpointClass::m_breakMap;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
dbgBreakpointClass::dbgBreakpointClass( ULONG64 offset ) HRESULT dbgBreakpointClass::onBreakpointEvnet( IDebugBreakpoint* bp )
{
try {
breakpointMap::iterator it = m_breakMap.find( bp );
if ( it != m_breakMap.end() )
return boost::python::extract<HRESULT>( it->second->m_callback() );
}
catch(...)
{}
return DEBUG_STATUS_NO_CHANGE;
}
///////////////////////////////////////////////////////////////////////////////
dbgBreakpointClass::dbgBreakpointClass( ULONG64 offset, boost::python::object &callback )
{ {
m_offset = offset; m_offset = offset;
m_breakpoint = NULL; m_breakpoint = NULL;
m_callback = callback;
set(); set();
} }
@ -165,6 +183,8 @@ dbgBreakpointClass::set()
if ( FAILED( hres ) ) if ( FAILED( hres ) )
throw DbgException( "IDebugBreakpoint::SetFlags failed" ); throw DbgException( "IDebugBreakpoint::SetFlags failed" );
m_breakMap.insert( std::make_pair( m_breakpoint, this ) );
return true; return true;
} }
catch( std::exception &e ) catch( std::exception &e )
@ -189,6 +209,11 @@ dbgBreakpointClass::remove()
if ( m_breakpoint ) if ( m_breakpoint )
{ {
dbgExt->control->RemoveBreakpoint( m_breakpoint ); dbgExt->control->RemoveBreakpoint( m_breakpoint );
breakpointMap::iterator bp = m_breakMap.find( m_breakpoint );
if ( bp != m_breakMap.end() )
m_breakMap.erase( bp );
m_breakpoint = NULL; m_breakpoint = NULL;
} }
} }
@ -285,3 +310,4 @@ evaluate( const std::string &expression )
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <string> #include <string>
#include <map>
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
@ -76,12 +77,11 @@ private:
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
class dbgBreakpointClass { class dbgBreakpointClass {
public: public:
dbgBreakpointClass( ULONG64 offset ); dbgBreakpointClass( ULONG64 offset, boost::python::object &callback );
~dbgBreakpointClass(); ~dbgBreakpointClass();
@ -100,6 +100,17 @@ private:
IDebugBreakpoint *m_breakpoint; IDebugBreakpoint *m_breakpoint;
boost::python::object m_callback;
private:
typedef std::map<IDebugBreakpoint*, dbgBreakpointClass*> breakpointMap;
static breakpointMap m_breakMap;
public:
static HRESULT onBreakpointEvnet( IDebugBreakpoint* bp );
}; };
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////

View File

@ -10,6 +10,7 @@
#include "dbgsystem.h" #include "dbgsystem.h"
#include "dbgcmd.h" #include "dbgcmd.h"
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
bool bool
@ -19,8 +20,16 @@ dbgLoadDump( const std::wstring &fileName )
try { try {
if ( !dbgSessionStarted ) if ( dbgExt )
dbgCreateSession(); return false;
IDebugClient4 *client = NULL;
hres = DebugCreate( __uuidof(IDebugClient4), (void **)&client );
if ( FAILED( hres ) )
return false;
dbgExt = new DbgExt( client );
new DbgEventCallbacksManager( (IDebugClient*)client );
hres = dbgExt->client4->OpenDumpFileWide( fileName.c_str(), NULL ); hres = dbgExt->client4->OpenDumpFileWide( fileName.c_str(), NULL );
@ -53,8 +62,16 @@ startProcess( const std::wstring &processName )
try { try {
if ( !dbgSessionStarted ) if ( dbgExt )
dbgCreateSession(); return false;
IDebugClient4 *client = NULL;
hres = DebugCreate( __uuidof(IDebugClient4), (void **)&client );
if ( FAILED( hres ) )
return false;
dbgExt = new DbgExt( client );
new DbgEventCallbacksManager( (IDebugClient*)client );
ULONG opt; ULONG opt;
hres = dbgExt->control->GetEngineOptions( &opt ); hres = dbgExt->control->GetEngineOptions( &opt );

View File

@ -1,202 +1,120 @@
#include "stdafx.h" #include "stdafx.h"
#include "dbgeng.h"
#include "dbgext.h" #include "dbgext.h"
#include "dbgmem.h"
#include "dbgmodule.h"
#include "dbgexcept.h"
#include "dbgsynsym.h"
#include "dbgeventcb.h" #include "dbgeventcb.h"
#include "dbgexcept.h"
#include "dbgmodule.h"
#include "dbgsynsym.h"
#include "dbgcmd.h"
///////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
DbgEventCallbacks *DbgEventCallbacks::dbgEventCallbacks = NULL; DbgEventCallbacksManager::DbgEventCallbacksManager( IDebugClient *client )
volatile LONG DbgEventCallbacks::dbgEventCallbacksStartCount = 0;
/////////////////////////////////////////////////////////////////////////////////
HRESULT DbgEventCallbacks::Start()
{ {
HRESULT hres; HRESULT hres;
try
m_debugClient = NULL;
try {
if ( client == NULL )
{ {
if (1 == InterlockedIncrement(&dbgEventCallbacksStartCount)) // ñëó÷àé, êîãäà ìû ðàáîòàåì â windbg. Ìû íå õîòèì ìåíÿòü ïîâåäåíèå êëèåíòà îòëàä÷èêà - îí
{ // äîëæåí ïðîäîëæàòü îáðàáîòêó ñîáûòèé, ïîýòîìó ìû ñîçäàåì ñâîåãî êëèåíòà
_ASSERT(!dbgEventCallbacks); hres = DebugCreate( __uuidof(IDebugClient4), reinterpret_cast<PVOID*>(&m_debugClient));
dbgEventCallbacks = new DbgEventCallbacks; if (FAILED(hres))
throw DbgException( "DebugCreate failed" );
} }
hres = S_OK; else
}
catch (HRESULT _hres)
{ {
hres = _hres; // ñëó÷àé, êîãäà ìû ðàáîòàåì îòäåëüíî.  ýòîì ñëó÷àå êëèåíò âåñü â íàøåì ðàñïîðÿæåíèè
hres =client->QueryInterface( __uuidof(IDebugClient4), reinterpret_cast<PVOID*>(&m_debugClient));
if (FAILED(hres))
throw DbgException( "DebugCreate failed" );
}
hres = m_debugClient->SetEventCallbacks(this);
if (FAILED(hres))
throw DbgException( "IDebugClient::SetEventCallbacks" );
}
catch( std::exception& )
{
//dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() );
} }
catch(...) catch(...)
{ {
hres = E_OUTOFMEMORY; //dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" );
} }
return hres;
} }
///////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
void DbgEventCallbacks::Stop() DbgEventCallbacksManager::~DbgEventCallbacksManager()
{ {
if (0 == InterlockedDecrement(&dbgEventCallbacksStartCount)) if ( m_debugClient )
{ m_debugClient->Release();
_ASSERT(dbgEventCallbacks);
if (dbgEventCallbacks)
dbgEventCallbacks->Deregister();
}
} }
///////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
DbgEventCallbacks::DbgEventCallbacks() HRESULT DbgEventCallbacksManager::GetInterestMask(
: m_ReferenceCount(1)
, m_dbgClient(NULL)
, m_dbgSymbols3(NULL)
, m_dbgControl(NULL)
{
HRESULT hres;
try
{
// monitor "global" WinDbg events
hres = DebugCreate(
__uuidof(IDebugClient),
reinterpret_cast<PVOID *>(&m_dbgClient));
if (FAILED(hres))
throw hres;
hres = m_dbgClient->QueryInterface(
__uuidof(IDebugSymbols3),
reinterpret_cast<PVOID *>(&m_dbgSymbols3));
if (FAILED(hres))
throw hres;
hres = m_dbgClient->QueryInterface(
__uuidof(IDebugControl),
reinterpret_cast<PVOID *>(&m_dbgControl));
if (FAILED(hres))
throw hres;
hres = m_dbgClient->SetEventCallbacks(this);
if (FAILED(hres))
throw hres;
hres = S_OK;
}
catch(HRESULT _hres)
{
hres = _hres;
}
catch(...)
{
hres = S_FALSE;
}
if (S_OK != hres)
{
Deregister();
throw hres;
}
}
/////////////////////////////////////////////////////////////////////////////////
void DbgEventCallbacks::Deregister()
{
if (m_dbgSymbols3)
{
m_dbgSymbols3->Release();
m_dbgSymbols3 = NULL;
}
if (m_dbgControl)
{
m_dbgControl->Release();
m_dbgControl = NULL;
}
if (m_dbgClient)
{
m_dbgClient->Release();
m_dbgClient = NULL;
}
Release();
}
/////////////////////////////////////////////////////////////////////////////////
ULONG DbgEventCallbacks::AddRef()
{
return InterlockedIncrement(&m_ReferenceCount);
}
/////////////////////////////////////////////////////////////////////////////////
ULONG DbgEventCallbacks::Release()
{
ULONG nResult = InterlockedDecrement(&m_ReferenceCount);
if (!nResult)
{
dbgEventCallbacks = NULL;
delete this;
}
return nResult;
}
/////////////////////////////////////////////////////////////////////////////////
HRESULT DbgEventCallbacks::GetInterestMask(
__out PULONG Mask __out PULONG Mask
) )
{ {
*Mask = DEBUG_EVENT_CHANGE_SYMBOL_STATE; *Mask = DEBUG_EVENT_CHANGE_SYMBOL_STATE | DEBUG_EVENT_BREAKPOINT;
return S_OK; return S_OK;
} }
///////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
HRESULT DbgEventCallbacks::ChangeSymbolState( HRESULT DbgEventCallbacksManager::ChangeSymbolState(
__in ULONG Flags, __in ULONG Flags,
__in ULONG64 Argument __in ULONG64 Argument
) )
{ {
DbgExt ext( m_debugClient );
if ((DEBUG_CSS_LOADS & Flags)) if ((DEBUG_CSS_LOADS & Flags))
{ {
if (Argument) if (Argument)
return doSymbolsLoaded(Argument);
// f.e. is case ".reload /f image.exe", if for image.exe no symbols
restoreSyntheticSymbolForAllModules(m_dbgSymbols3, m_dbgControl);
return S_OK;
}
return S_OK;
}
/////////////////////////////////////////////////////////////////////////////////
HRESULT DbgEventCallbacks::doSymbolsLoaded(
ULONG64 moduleBase
)
{ {
try DEBUG_MODULE_PARAMETERS dbgModuleParameters={};
{
DEBUG_MODULE_PARAMETERS dbgModuleParameters; HRESULT hres = dbgExt->symbols3->GetModuleParameters(
HRESULT hres = m_dbgSymbols3->GetModuleParameters(
1, 1,
&moduleBase, &Argument,
0, 0,
&dbgModuleParameters); &dbgModuleParameters);
if (SUCCEEDED(hres)) if (SUCCEEDED(hres))
{ {
ModuleInfo moduleInfo(dbgModuleParameters, m_dbgControl); ModuleInfo moduleInfo(dbgModuleParameters);
restoreSyntheticSymbolForModule(moduleInfo, m_dbgSymbols3);
} restoreSyntheticSymbolForModule(moduleInfo);
}
catch (...)
{
} }
return S_OK; return S_OK;
} }
///////////////////////////////////////////////////////////////////////////////// //// f.e. is case ".reload /f image.exe", if for image.exe no symbols
restoreSyntheticSymbolForAllModules();
return S_OK;
}
return S_OK;
}
///////////////////////////////////////////////////////////////////////////////////
HRESULT DbgEventCallbacksManager::Breakpoint(
__in IDebugBreakpoint * bp
)
{
return dbgBreakpointClass::onBreakpointEvnet( bp );
}
///////////////////////////////////////////////////////////////////////////////////

View File

@ -1,25 +1,24 @@
#pragma once #pragma once
//////////////////////////////////////////////////////////////////////////////
// monitoring and processing debug events // monitoring and processing debug events
class DbgEventCallbacks : public DebugBaseEventCallbacks class DbgEventCallbacksManager : public DebugBaseEventCallbacks
{ {
public: public:
static HRESULT Start(); DbgEventCallbacksManager( IDebugClient *client = NULL );
static void Stop();
virtual ~DbgEventCallbacksManager();
private: private:
// may generate HRESULT exception if not registered
DbgEventCallbacks();
void Deregister();
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
// IUnknown interface implementation // IUnknown interface implementation
STDMETHOD_(ULONG, AddRef)(); STDMETHOD_(ULONG, AddRef)() { return 1; }
STDMETHOD_(ULONG, Release)(); STDMETHOD_(ULONG, Release)() { return 1; }
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
// IDebugEventCallbacks interface implementation // IDebugEventCallbacks interface implementation
@ -33,25 +32,13 @@ private:
__in ULONG64 Argument __in ULONG64 Argument
); );
///////////////////////////////////////////////////////////////////////////////// STDMETHOD(Breakpoint)(
__in PDEBUG_BREAKPOINT Bp
HRESULT doSymbolsLoaded(
ULONG64 moduleBase
); );
///////////////////////////////////////////////////////////////////////////////// private:
volatile LONG m_ReferenceCount; IDebugClient4 *m_debugClient;
IDebugClient *m_dbgClient;
IDebugSymbols3 *m_dbgSymbols3;
IDebugControl *m_dbgControl;
/////////////////////////////////////////////////////////////////////////////////
// global singleton
static DbgEventCallbacks *dbgEventCallbacks;
static volatile LONG dbgEventCallbacksStartCount;
/////////////////////////////////////////////////////////////////////////////////
}; };
//////////////////////////////////////////////////////////////////////////////

View File

@ -29,48 +29,15 @@
#include "dbgprocess.h" #include "dbgprocess.h"
#include "dbgsynsym.h" #include "dbgsynsym.h"
///////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// óêàçàòåëü íà òåêóùéè èíòåðôåéñ // óêàçàòåëü íà òåêóùèé èíòåðôåéñ
DbgExt *dbgExt = NULL; DbgExt *dbgExt = NULL;
static bool isWindbgExt();
///////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
class WindbgGlobalSession
{
public:
WindbgGlobalSession() {
boost::python::import( "pykd" );
main = boost::python::import("__main__");
// ïåðåíàïðàâëåíèå ñòàíäàðòíûõ ïîòîêîâ ÂÂ
boost::python::object sys = boost::python::import( "sys");
dbgOut dout;
sys.attr("stdout") = boost::python::object( dout );
dbgIn din;
sys.attr("stdin") = boost::python::object( din );
}
boost::python::object
global() {
return main.attr("__dict__");
}
private:
boost::python::object main;
};
WindbgGlobalSession *windbgGlobalSession = NULL;
/////////////////////////////////////////////////////////////////////////////////
BOOST_PYTHON_FUNCTION_OVERLOADS( dprint, DbgPrint::dprint, 1, 2 ) BOOST_PYTHON_FUNCTION_OVERLOADS( dprint, DbgPrint::dprint, 1, 2 )
BOOST_PYTHON_FUNCTION_OVERLOADS( dprintln, DbgPrint::dprintln, 1, 2 ) BOOST_PYTHON_FUNCTION_OVERLOADS( dprintln, DbgPrint::dprintln, 1, 2 )
@ -94,8 +61,8 @@ BOOST_PYTHON_MODULE( pykd )
boost::python::def( "trace", &setExecutionStatus<DEBUG_STATUS_STEP_INTO> ); boost::python::def( "trace", &setExecutionStatus<DEBUG_STATUS_STEP_INTO> );
boost::python::def( "step", &setExecutionStatus<DEBUG_STATUS_STEP_OVER> ); boost::python::def( "step", &setExecutionStatus<DEBUG_STATUS_STEP_OVER> );
boost::python::def( "expr", &evaluate ); boost::python::def( "expr", &evaluate );
boost::python::def( "createSession", &dbgCreateSession ); // deprecated boost::python::def( "isWindbgExt", &isWindbgExt );
boost::python::def( "isSessionStart", &dbgIsSessionStart ); boost::python::def( "isSessionStart", &isWindbgExt );
boost::python::def( "symbolsPath", &dbgSymPath ); boost::python::def( "symbolsPath", &dbgSymPath );
boost::python::def( "dprint", &DbgPrint::dprint, dprint( boost::python::args( "str", "dml" ), "" ) ); 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( "dprintln", &DbgPrint::dprintln, dprintln( boost::python::args( "str", "dml" ), "" ) );
@ -200,7 +167,7 @@ BOOST_PYTHON_MODULE( pykd )
boost::python::class_<dbgBreakpointClass>( boost::python::class_<dbgBreakpointClass>(
"bp", "bp",
"break point", "break point",
boost::python::init<ULONG64>( boost::python::args("offset"), "__init__ dbgBreakpointClass" ) ) boost::python::init<ULONG64,boost::python::object&>( boost::python::args("offset", "callback"), "__init__ dbgBreakpointClass" ) )
.def( "set", &dbgBreakpointClass::set ) .def( "set", &dbgBreakpointClass::set )
.def( "remove", &dbgBreakpointClass::remove ) .def( "remove", &dbgBreakpointClass::remove )
.def( "__str__", &dbgBreakpointClass::print ); .def( "__str__", &dbgBreakpointClass::print );
@ -268,6 +235,86 @@ BOOST_PYTHON_MODULE( pykd )
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
class WindbgGlobalSession
{
public:
static
boost::python::object
global() {
return windbgGlobalSession->main.attr("__dict__");
}
static
VOID
StartWindbgSession() {
if ( 1 == InterlockedIncrement( &sessionCount ) )
{
windbgGlobalSession = new WindbgGlobalSession();
}
}
static
VOID
StopWindbgSession() {
if ( 0 == InterlockedDecrement( &sessionCount ) )
{
delete windbgGlobalSession;
windbgGlobalSession = NULL;
}
}
static
bool isInit() {
return windbgGlobalSession != NULL;
}
private:
WindbgGlobalSession() {
PyImport_AppendInittab("pykd", initpykd );
Py_Initialize();
boost::python::import( "pykd" );
main = boost::python::import("__main__");
// ïåðåíàïðàâëåíèå ñòàíäàðòíûõ ïîòîêîâ ÂÂ
boost::python::object sys = boost::python::import( "sys");
dbgOut dout;
sys.attr("stdout") = boost::python::object( dout );
dbgIn din;
sys.attr("stdin") = boost::python::object( din );
}
~WindbgGlobalSession() {
Py_Finalize();
}
boost::python::object main;
DbgEventCallbacksManager callbackMgr;
static volatile LONG sessionCount;
static WindbgGlobalSession *windbgGlobalSession;
};
volatile LONG WindbgGlobalSession::sessionCount = 0;
WindbgGlobalSession *WindbgGlobalSession::windbgGlobalSession = NULL;
bool isWindbgExt() {
return WindbgGlobalSession::isInit();
}
/////////////////////////////////////////////////////////////////////////////////
HRESULT HRESULT
CALLBACK CALLBACK
DebugExtensionInitialize( DebugExtensionInitialize(
@ -277,13 +324,9 @@ DebugExtensionInitialize(
*Version = DEBUG_EXTENSION_VERSION( 1, 0 ); *Version = DEBUG_EXTENSION_VERSION( 1, 0 );
*Flags = 0; *Flags = 0;
PyImport_AppendInittab("pykd", initpykd ); WindbgGlobalSession::StartWindbgSession();
Py_Initialize(); return S_OK;
windbgGlobalSession = new WindbgGlobalSession();
return setDbgSessionStarted();
} }
@ -291,38 +334,34 @@ VOID
CALLBACK CALLBACK
DebugExtensionUninitialize() DebugExtensionUninitialize()
{ {
DbgEventCallbacks::Stop(); WindbgGlobalSession::StopWindbgSession();
delete windbgGlobalSession;
windbgGlobalSession = NULL;
Py_Finalize();
} }
DbgExt::DbgExt( IDebugClient4 *masterClient )
void
SetupDebugEngine( IDebugClient4 *client, DbgExt *dbgExt )
{ {
client->QueryInterface( __uuidof(IDebugClient), (void **)&dbgExt->client ); masterClient->QueryInterface( __uuidof(IDebugClient), (void **)&client );
client->QueryInterface( __uuidof(IDebugClient4), (void **)&dbgExt->client4 ); masterClient->QueryInterface( __uuidof(IDebugClient4), (void **)&client4 );
client->QueryInterface( __uuidof(IDebugControl), (void **)&dbgExt->control ); masterClient->QueryInterface( __uuidof(IDebugControl), (void **)&control );
client->QueryInterface( __uuidof(IDebugControl4), (void **)&dbgExt->control4 ); masterClient->QueryInterface( __uuidof(IDebugControl4), (void **)&control4 );
client->QueryInterface( __uuidof(IDebugRegisters), (void **)&dbgExt->registers ); masterClient->QueryInterface( __uuidof(IDebugRegisters), (void **)&registers );
client->QueryInterface( __uuidof(IDebugSymbols), (void ** )&dbgExt->symbols ); masterClient->QueryInterface( __uuidof(IDebugSymbols), (void ** )&symbols );
client->QueryInterface( __uuidof(IDebugSymbols2), (void ** )&dbgExt->symbols2 ); masterClient->QueryInterface( __uuidof(IDebugSymbols2), (void ** )&symbols2 );
client->QueryInterface( __uuidof(IDebugSymbols3), (void ** )&dbgExt->symbols3 ); masterClient->QueryInterface( __uuidof(IDebugSymbols3), (void ** )&symbols3 );
client->QueryInterface( __uuidof(IDebugDataSpaces), (void **)&dbgExt->dataSpaces ); masterClient->QueryInterface( __uuidof(IDebugDataSpaces), (void **)&dataSpaces );
client->QueryInterface( __uuidof(IDebugDataSpaces4), (void **)&dbgExt->dataSpaces4 ); masterClient->QueryInterface( __uuidof(IDebugDataSpaces4), (void **)&dataSpaces4 );
client->QueryInterface( __uuidof(IDebugAdvanced2), (void **)&dbgExt->advanced2 ); masterClient->QueryInterface( __uuidof(IDebugAdvanced2), (void **)&advanced2 );
client->QueryInterface( __uuidof(IDebugSystemObjects), (void**)&dbgExt->system ); masterClient->QueryInterface( __uuidof(IDebugSystemObjects), (void**)&system );
client->QueryInterface( __uuidof(IDebugSystemObjects2), (void**)&dbgExt->system2 ); masterClient->QueryInterface( __uuidof(IDebugSystemObjects2), (void**)&system2 );
m_previosExt = dbgExt;
dbgExt = this;
} }
DbgExt::~DbgExt() DbgExt::~DbgExt()
@ -365,6 +404,8 @@ DbgExt::~DbgExt()
if ( system2 ) if ( system2 )
system2->Release(); system2->Release();
dbgExt = m_previosExt;
} }
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
@ -373,16 +414,13 @@ HRESULT
CALLBACK CALLBACK
py( PDEBUG_CLIENT4 client, PCSTR args) py( PDEBUG_CLIENT4 client, PCSTR args)
{ {
DbgExt ext( client );
PyThreadState *globalInterpreter = PyThreadState_Swap( NULL ); PyThreadState *globalInterpreter = PyThreadState_Swap( NULL );
PyThreadState *localInterpreter = Py_NewInterpreter(); PyThreadState *localInterpreter = Py_NewInterpreter();
try { try {
DbgExt ext;
SetupDebugEngine( client, &ext );
dbgExt = &ext;
boost::python::import( "pykd" ); boost::python::import( "pykd" );
boost::python::object main = boost::python::import("__main__"); boost::python::object main = boost::python::import("__main__");
@ -495,16 +533,14 @@ pycmd( PDEBUG_CLIENT4 client, PCSTR args )
{ {
try { try {
DbgExt ext; DbgExt ext( client );
SetupDebugEngine( client, &ext );
dbgExt = &ext;
if ( !std::string( args ).empty() ) if ( !std::string( args ).empty() )
{ {
try try
{ {
boost::python::exec( args, windbgGlobalSession->global(), windbgGlobalSession->global() ); boost::python::exec( args, WindbgGlobalSession::global(), WindbgGlobalSession::global() );
} }
catch( boost::python::error_already_set const & ) catch( boost::python::error_already_set const & )
{ {
@ -555,7 +591,7 @@ pycmd( PDEBUG_CLIENT4 client, PCSTR args )
if ( !stopInput ) if ( !stopInput )
try { try {
boost::python::exec( str, windbgGlobalSession->global(), windbgGlobalSession->global() ); boost::python::exec( str, WindbgGlobalSession::global(), WindbgGlobalSession::global() );
} }
catch( boost::python::error_already_set const & ) catch( boost::python::error_already_set const & )
{ {
@ -596,12 +632,12 @@ HRESULT
CALLBACK CALLBACK
pythonpath( PDEBUG_CLIENT4 client, PCSTR args ) pythonpath( PDEBUG_CLIENT4 client, PCSTR args )
{ {
DbgExt ext; //DbgExt ext;
SetupDebugEngine( client, &ext ); //SetupDebugEngine( client, &ext );
dbgExt = &ext; //dbgExt = &ext;
//DbgPrint::dprintln( dbgPythonPath.getStr() ); ////DbgPrint::dprintln( dbgPythonPath.getStr() );
return S_OK; return S_OK;
} }

View File

@ -3,7 +3,9 @@
#include <dbgeng.h> #include <dbgeng.h>
#include <dbghelp.h> #include <dbghelp.h>
struct DbgExt { class DbgExt {
public:
IDebugClient *client; IDebugClient *client;
IDebugClient4 *client4; IDebugClient4 *client4;
@ -25,27 +27,14 @@ struct DbgExt {
IDebugSystemObjects *system; IDebugSystemObjects *system;
IDebugSystemObjects2 *system2; IDebugSystemObjects2 *system2;
DbgExt() : DbgExt( IDebugClient4 *client );
client( NULL ),
client4( NULL ),
control( NULL ),
control4( NULL ),
registers( NULL ),
symbols( NULL ),
symbols2( NULL ),
symbols3( NULL ),
dataSpaces( NULL ),
dataSpaces4( NULL ),
advanced2( NULL ),
system( NULL ),
system2( NULL )
{}
~DbgExt(); ~DbgExt();
private:
DbgExt *m_previosExt;
}; };
extern DbgExt *dbgExt; extern DbgExt *dbgExt;
void
SetupDebugEngine( IDebugClient4 *client, DbgExt *dbgExt );

View File

@ -3,6 +3,9 @@
#include <string> #include <string>
#include <map> #include <map>
#include "dbgext.h"
#include "dbgmem.h"
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
// global unique module data // global unique module data

View File

@ -1,27 +1,27 @@
#include "stdafx.h" #include "stdafx.h"
#include "dbgext.h" //#include "dbgext.h"
#include "dbgeventcb.h" //#include "dbgeventcb.h"
#include "dbgsession.h" //#include "dbgsession.h"
//
DbgExt dbgGlobalSession; //DbgExt dbgGlobalSession;
//
bool dbgSessionStarted = false; //bool dbgSessionStarted = false;
//
void //void
dbgCreateSession() //dbgCreateSession()
{ //{
IDebugClient4 *client = NULL; // IDebugClient4 *client = NULL;
DebugCreate( __uuidof(IDebugClient4), (void **)&client ); // DebugCreate( __uuidof(IDebugClient4), (void **)&client );
//
SetupDebugEngine( client, &dbgGlobalSession ); // SetupDebugEngine( client, &dbgGlobalSession );
dbgExt = &dbgGlobalSession; // dbgExt = &dbgGlobalSession;
//
setDbgSessionStarted(); // setDbgSessionStarted();
} //}
//
bool //bool
dbgIsSessionStart() //dbgIsSessionStart()
{ //{
return dbgSessionStarted; // return dbgSessionStarted;
} //}

View File

@ -1,19 +1,19 @@
#pragma once #pragma once
void //void
dbgCreateSession(); //dbgCreateSession();
//
extern //extern
bool dbgSessionStarted; //bool dbgSessionStarted;
//
inline HRESULT setDbgSessionStarted() //inline HRESULT setDbgSessionStarted()
{ //{
HRESULT hres = DbgEventCallbacks::Start(); // HRESULT hres = DbgEventCallbacks::Start();
if (SUCCEEDED(hres)) // if (SUCCEEDED(hres))
dbgSessionStarted = true; // dbgSessionStarted = true;
return hres; // return hres;
} //}
//
bool //bool
dbgIsSessionStart(); //dbgIsSessionStart();

View File

@ -574,8 +574,7 @@ ULONG delSyntheticSymbolsMask(
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
static void restoreSyntheticSymbolForModuleNoLock( static void restoreSyntheticSymbolForModuleNoLock(
const ModuleInfo &moduleInfo, const ModuleInfo &moduleInfo
IDebugSymbols3 *symbols3
) )
{ {
SynSymbolsMap::const_iterator itSynSymbols = SynSymbolsMap::const_iterator itSynSymbols =
@ -587,7 +586,7 @@ static void restoreSyntheticSymbolForModuleNoLock(
while (itSynSymbol != itSynSymbols->second.end()) while (itSynSymbol != itSynSymbols->second.end())
{ {
DEBUG_MODULE_AND_ID dbgModuleAndId; DEBUG_MODULE_AND_ID dbgModuleAndId;
symbols3->AddSyntheticSymbol( dbgExt->symbols3->AddSyntheticSymbol(
moduleInfo.m_base + itSynSymbol->first, moduleInfo.m_base + itSynSymbol->first,
itSynSymbol->second.m_size, itSynSymbol->second.m_size,
itSynSymbol->second.m_name.c_str(), itSynSymbol->second.m_name.c_str(),
@ -602,22 +601,18 @@ static void restoreSyntheticSymbolForModuleNoLock(
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
void restoreSyntheticSymbolForModule( void restoreSyntheticSymbolForModule(
const ModuleInfo &moduleInfo, const ModuleInfo &moduleInfo
IDebugSymbols3 *symbols3
) )
{ {
_SynSymbolsMapScopedLock(); _SynSymbolsMapScopedLock();
// see (**1) // see (**1)
restoreSyntheticSymbolForModuleNoLock(moduleInfo, symbols3); restoreSyntheticSymbolForModuleNoLock(moduleInfo);
} }
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
void restoreSyntheticSymbolForAllModules( void restoreSyntheticSymbolForAllModules()
IDebugSymbols3 *symbols3,
IDebugControl *control
)
{ {
try try
{ {
@ -629,12 +624,12 @@ void restoreSyntheticSymbolForAllModules(
ULONG nLoaded; ULONG nLoaded;
ULONG nUnloaded; ULONG nUnloaded;
HRESULT hres = symbols3->GetNumberModules(&nLoaded, &nUnloaded); HRESULT hres = dbgExt->symbols3->GetNumberModules(&nLoaded, &nUnloaded);
if (SUCCEEDED(hres) && (nLoaded || nUnloaded)) if (SUCCEEDED(hres) && (nLoaded || nUnloaded))
{ {
std::vector<DEBUG_MODULE_PARAMETERS> arrModules(nLoaded + nUnloaded); std::vector<DEBUG_MODULE_PARAMETERS> arrModules(nLoaded + nUnloaded);
hres = hres =
symbols3->GetModuleParameters( dbgExt->symbols3->GetModuleParameters(
(ULONG)arrModules.size(), (ULONG)arrModules.size(),
NULL, NULL,
0, 0,
@ -643,8 +638,8 @@ void restoreSyntheticSymbolForAllModules(
{ {
for (ULONG i = 0; i < arrModules.size(); ++i) for (ULONG i = 0; i < arrModules.size(); ++i)
{ {
ModuleInfo moduleInfo(arrModules[i], control); ModuleInfo moduleInfo(arrModules[i]);
restoreSyntheticSymbolForModuleNoLock(moduleInfo, symbols3); restoreSyntheticSymbolForModuleNoLock(moduleInfo);
} }
} }
} }

View File

@ -49,13 +49,8 @@ void delAllSyntheticSymbolsForModule(
// External callbacks // External callbacks
void restoreSyntheticSymbolForModule( void restoreSyntheticSymbolForModule(
const ModuleInfo &moduleInfo, const ModuleInfo &moduleInfo );
IDebugSymbols3 *symbols3
);
void restoreSyntheticSymbolForAllModules( void restoreSyntheticSymbolForAllModules();
IDebugSymbols3 *symbols3,
IDebugControl *control
);
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="windows-1251"?> <?xml version="1.0" encoding="windows-1251"?>
<VisualStudioProject <VisualStudioProject
ProjectType="Visual C++" ProjectType="Visual C++"
Version="8.00" Version="8,00"
Name="pykd" Name="pykd"
ProjectGUID="{C0A12E93-4B76-4B17-B837-37020F957AD2}" ProjectGUID="{C0A12E93-4B76-4B17-B837-37020F957AD2}"
RootNamespace="pykd" RootNamespace="pykd"
@ -396,10 +396,6 @@
RelativePath=".\dbgreg.cpp" RelativePath=".\dbgreg.cpp"
> >
</File> </File>
<File
RelativePath=".\dbgsession.cpp"
>
</File>
<File <File
RelativePath=".\dbgsym.cpp" RelativePath=".\dbgsym.cpp"
> >