mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-20 03:23:23 +08:00
[pykd] fixed: issue 8470 ( python.exe crashes after first pykd call )
git-svn-id: https://pykd.svn.codeplex.com/svn@63970 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
parent
5371048a72
commit
1d27cb91d7
49
pykd/dbgclient.h
Normal file
49
pykd/dbgclient.h
Normal file
@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
|
||||
#include "dbgext.h"
|
||||
#include "dbgeventcb.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class dbgClient {
|
||||
|
||||
public:
|
||||
|
||||
dbgClient()
|
||||
{
|
||||
IDebugClient4 *client = NULL;
|
||||
DebugCreate( __uuidof(IDebugClient4), (void **)&client );
|
||||
|
||||
m_ext = new DbgExt( client );
|
||||
}
|
||||
|
||||
~dbgClient()
|
||||
{
|
||||
removeEventsMgr();
|
||||
|
||||
delete m_ext;
|
||||
}
|
||||
|
||||
void startEventsMgr() {
|
||||
|
||||
m_callbacks = new DbgEventCallbacksManager( m_ext->client );
|
||||
}
|
||||
|
||||
void removeEventsMgr() {
|
||||
|
||||
if ( m_callbacks )
|
||||
{
|
||||
delete m_callbacks;
|
||||
m_callbacks = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
DbgExt *m_ext;
|
||||
DbgEventCallbacksManager *m_callbacks;
|
||||
};
|
||||
|
||||
extern dbgClient g_dbgClient;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
@ -6,9 +6,14 @@
|
||||
#include "dbgdump.h"
|
||||
#include "dbgexcept.h"
|
||||
#include "dbgeventcb.h"
|
||||
#include "dbgsession.h"
|
||||
#include "dbgsystem.h"
|
||||
#include "dbgcmd.h"
|
||||
#include "dbgclient.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static
|
||||
bool dbgStarted = false;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
@ -20,16 +25,10 @@ dbgLoadDump( const std::wstring &fileName )
|
||||
|
||||
try {
|
||||
|
||||
if ( dbgExt )
|
||||
if ( dbgStarted || isWindbgExt() )
|
||||
return false;
|
||||
|
||||
IDebugClient4 *client = NULL;
|
||||
hres = DebugCreate( __uuidof(IDebugClient4), (void **)&client );
|
||||
if ( FAILED( hres ) )
|
||||
return false;
|
||||
|
||||
dbgExt = new DbgExt( client );
|
||||
new DbgEventCallbacksManager( (IDebugClient*)client );
|
||||
g_dbgClient.startEventsMgr();
|
||||
|
||||
hres = dbgExt->client4->OpenDumpFileWide( fileName.c_str(), NULL );
|
||||
|
||||
@ -40,6 +39,8 @@ dbgLoadDump( const std::wstring &fileName )
|
||||
if ( FAILED( hres ) )
|
||||
throw DbgException( "IDebugControl::WaitForEvent failed" );
|
||||
|
||||
dbgStarted = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
catch( std::exception& )
|
||||
@ -62,16 +63,10 @@ startProcess( const std::wstring &processName )
|
||||
|
||||
try {
|
||||
|
||||
if ( dbgExt )
|
||||
if ( dbgStarted || isWindbgExt() )
|
||||
return false;
|
||||
|
||||
IDebugClient4 *client = NULL;
|
||||
hres = DebugCreate( __uuidof(IDebugClient4), (void **)&client );
|
||||
if ( FAILED( hres ) )
|
||||
return false;
|
||||
|
||||
dbgExt = new DbgExt( client );
|
||||
new DbgEventCallbacksManager( (IDebugClient*)client );
|
||||
g_dbgClient.startEventsMgr();
|
||||
|
||||
ULONG opt;
|
||||
hres = dbgExt->control->GetEngineOptions( &opt );
|
||||
@ -94,6 +89,8 @@ startProcess( const std::wstring &processName )
|
||||
if ( FAILED( hres ) )
|
||||
throw DbgException( "IDebugControl::WaitForEvent failed" );
|
||||
|
||||
dbgStarted = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
catch( std::exception& e )
|
||||
|
@ -14,38 +14,23 @@ DbgEventCallbacksManager::DbgEventCallbacksManager( IDebugClient *client )
|
||||
{
|
||||
HRESULT hres;
|
||||
|
||||
m_debugClient = NULL;
|
||||
|
||||
try {
|
||||
|
||||
if ( client == NULL )
|
||||
{
|
||||
// ñëó÷àé, êîãäà ìû ðàáîòàåì â windbg. Ìû íå õîòèì ìåíÿòü ïîâåäåíèå êëèåíòà îòëàä÷èêà - îí
|
||||
// äîëæåí ïðîäîëæàòü îáðàáîòêó ñîáûòèé, ïîýòîìó ìû ñîçäàåì ñâîåãî êëèåíòà
|
||||
hres = DebugCreate( __uuidof(IDebugClient4), reinterpret_cast<PVOID*>(&m_debugClient));
|
||||
if (FAILED(hres))
|
||||
throw DbgException( "DebugCreate failed" );
|
||||
}
|
||||
else
|
||||
{
|
||||
// ñëó÷àé, êîãäà ìû ðàáîòàåì îòäåëüíî.  ýòîì ñëó÷àå êëèåíò âåñü â íàøåì ðàñïîðÿæåíèè
|
||||
hres =client->QueryInterface( __uuidof(IDebugClient4), reinterpret_cast<PVOID*>(&m_debugClient));
|
||||
if (FAILED(hres))
|
||||
throw DbgException( "DebugCreate failed" );
|
||||
}
|
||||
m_debugClient = client;
|
||||
m_debugClient->AddRef();
|
||||
|
||||
hres = m_debugClient->SetEventCallbacks(this);
|
||||
if (FAILED(hres))
|
||||
throw DbgException( "IDebugClient::SetEventCallbacks" );
|
||||
|
||||
}
|
||||
catch( std::exception& )
|
||||
catch( std::exception& e)
|
||||
{
|
||||
//dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() );
|
||||
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() );
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
//dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" );
|
||||
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" );
|
||||
}
|
||||
}
|
||||
|
||||
@ -74,8 +59,6 @@ HRESULT DbgEventCallbacksManager::ChangeSymbolState(
|
||||
__in ULONG64 Argument
|
||||
)
|
||||
{
|
||||
DbgExt ext( m_debugClient );
|
||||
|
||||
if ((DEBUG_CSS_LOADS & Flags))
|
||||
{
|
||||
if (Argument)
|
||||
|
@ -38,7 +38,7 @@ private:
|
||||
|
||||
private:
|
||||
|
||||
IDebugClient4 *m_debugClient;
|
||||
IDebugClient *m_debugClient;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
@ -22,19 +22,20 @@
|
||||
#include "dbgdump.h"
|
||||
#include "dbgexcept.h"
|
||||
#include "dbgeventcb.h"
|
||||
#include "dbgsession.h"
|
||||
#include "dbgcallback.h"
|
||||
#include "dbgpath.h"
|
||||
#include "dbginput.h"
|
||||
#include "dbgprocess.h"
|
||||
#include "dbgsynsym.h"
|
||||
#include "dbgclient.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// óêàçàòåëü íà òåêóùèé èíòåðôåéñ
|
||||
DbgExt *dbgExt = NULL;
|
||||
|
||||
static bool isWindbgExt();
|
||||
// ãëîáàëüíûé êëèåíò
|
||||
dbgClient g_dbgClient;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -399,19 +400,20 @@ private:
|
||||
|
||||
dbgIn din;
|
||||
sys.attr("stdin") = boost::python::object( din );
|
||||
|
||||
g_dbgClient.startEventsMgr();
|
||||
}
|
||||
|
||||
~WindbgGlobalSession() {
|
||||
Py_Finalize();
|
||||
g_dbgClient.removeEventsMgr();
|
||||
}
|
||||
|
||||
boost::python::object main;
|
||||
|
||||
DbgEventCallbacksManager callbackMgr;
|
||||
|
||||
static volatile LONG sessionCount;
|
||||
|
||||
static WindbgGlobalSession *windbgGlobalSession;
|
||||
static WindbgGlobalSession *windbgGlobalSession;
|
||||
};
|
||||
|
||||
volatile LONG WindbgGlobalSession::sessionCount = 0;
|
||||
@ -634,11 +636,12 @@ pycmd( PDEBUG_CLIENT4 client, PCSTR args )
|
||||
|
||||
DbgExt ext( client );
|
||||
|
||||
|
||||
if ( !std::string( args ).empty() )
|
||||
{
|
||||
try
|
||||
{
|
||||
OutputReader outputReader( dbgExt->client );
|
||||
|
||||
boost::python::exec( args, WindbgGlobalSession::global(), WindbgGlobalSession::global() );
|
||||
}
|
||||
catch( boost::python::error_already_set const & )
|
||||
@ -676,7 +679,7 @@ pycmd( PDEBUG_CLIENT4 client, PCSTR args )
|
||||
|
||||
do {
|
||||
|
||||
OutputReader outputReader( dbgExt->client );
|
||||
OutputReader outputReader( (IDebugClient*)client );
|
||||
|
||||
HRESULT hres = dbgExt->control->Input( str, sizeof(str), &inputSize );
|
||||
|
||||
|
@ -38,3 +38,5 @@ private:
|
||||
|
||||
extern DbgExt *dbgExt;
|
||||
|
||||
|
||||
bool isWindbgExt();
|
||||
|
@ -1,27 +0,0 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
//#include "dbgext.h"
|
||||
//#include "dbgeventcb.h"
|
||||
//#include "dbgsession.h"
|
||||
//
|
||||
//DbgExt dbgGlobalSession;
|
||||
//
|
||||
//bool dbgSessionStarted = false;
|
||||
//
|
||||
//void
|
||||
//dbgCreateSession()
|
||||
//{
|
||||
// IDebugClient4 *client = NULL;
|
||||
// DebugCreate( __uuidof(IDebugClient4), (void **)&client );
|
||||
//
|
||||
// SetupDebugEngine( client, &dbgGlobalSession );
|
||||
// dbgExt = &dbgGlobalSession;
|
||||
//
|
||||
// setDbgSessionStarted();
|
||||
//}
|
||||
//
|
||||
//bool
|
||||
//dbgIsSessionStart()
|
||||
//{
|
||||
// return dbgSessionStarted;
|
||||
//}
|
@ -1,19 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
//void
|
||||
//dbgCreateSession();
|
||||
//
|
||||
//extern
|
||||
//bool dbgSessionStarted;
|
||||
//
|
||||
//inline HRESULT setDbgSessionStarted()
|
||||
//{
|
||||
// HRESULT hres = DbgEventCallbacks::Start();
|
||||
// if (SUCCEEDED(hres))
|
||||
// dbgSessionStarted = true;
|
||||
// return hres;
|
||||
//}
|
||||
//
|
||||
//bool
|
||||
//dbgIsSessionStart();
|
||||
|
@ -462,6 +462,10 @@
|
||||
RelativePath=".\dbgcallback.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\dbgclient.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\dbgcmd.h"
|
||||
>
|
||||
@ -510,10 +514,6 @@
|
||||
RelativePath=".\dbgreg.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\dbgsession.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\dbgsym.h"
|
||||
>
|
||||
|
Loading…
Reference in New Issue
Block a user