[+] added addr64Ex(...) with IDebugControl

[~] work-around for secondary DebugExtensionInitialize call
[~] addr64(...) in events filter replaced to addr64Ex(...)

git-svn-id: https://pykd.svn.codeplex.com/svn@63271 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\EreTIk_cp 2011-03-30 12:57:53 +00:00
parent 30bbc70403
commit 946f6cdc1f
7 changed files with 50 additions and 14 deletions

View File

@ -11,6 +11,7 @@
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
DbgEventCallbacks *DbgEventCallbacks::dbgEventCallbacks = NULL; DbgEventCallbacks *DbgEventCallbacks::dbgEventCallbacks = NULL;
volatile LONG DbgEventCallbacks::dbgEventCallbacksStartCount = 0;
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
@ -19,8 +20,11 @@ HRESULT DbgEventCallbacks::Start()
HRESULT hres; HRESULT hres;
try try
{ {
Stop(); if (1 == InterlockedIncrement(&dbgEventCallbacksStartCount))
dbgEventCallbacks = new DbgEventCallbacks; {
_ASSERT(!dbgEventCallbacks);
dbgEventCallbacks = new DbgEventCallbacks;
}
hres = S_OK; hres = S_OK;
} }
catch (HRESULT _hres) catch (HRESULT _hres)
@ -38,8 +42,12 @@ HRESULT DbgEventCallbacks::Start()
void DbgEventCallbacks::Stop() void DbgEventCallbacks::Stop()
{ {
if (dbgEventCallbacks) if (0 == InterlockedDecrement(&dbgEventCallbacksStartCount))
dbgEventCallbacks->Deregister(); {
_ASSERT(dbgEventCallbacks);
if (dbgEventCallbacks)
dbgEventCallbacks->Deregister();
}
} }
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
@ -48,6 +56,7 @@ DbgEventCallbacks::DbgEventCallbacks()
: m_ReferenceCount(1) : m_ReferenceCount(1)
, m_dbgClient(NULL) , m_dbgClient(NULL)
, m_dbgSymbols3(NULL) , m_dbgSymbols3(NULL)
, m_dbgControl(NULL)
{ {
HRESULT hres; HRESULT hres;
try try
@ -65,6 +74,12 @@ DbgEventCallbacks::DbgEventCallbacks()
if (FAILED(hres)) if (FAILED(hres))
throw hres; throw hres;
hres = m_dbgClient->QueryInterface(
__uuidof(IDebugControl),
reinterpret_cast<PVOID *>(&m_dbgControl));
if (FAILED(hres))
throw hres;
hres = m_dbgClient->SetEventCallbacks(this); hres = m_dbgClient->SetEventCallbacks(this);
if (FAILED(hres)) if (FAILED(hres))
throw hres; throw hres;
@ -95,6 +110,11 @@ void DbgEventCallbacks::Deregister()
m_dbgSymbols3->Release(); m_dbgSymbols3->Release();
m_dbgSymbols3 = NULL; m_dbgSymbols3 = NULL;
} }
if (m_dbgControl)
{
m_dbgControl->Release();
m_dbgControl = NULL;
}
if (m_dbgClient) if (m_dbgClient)
{ {
m_dbgClient->Release(); m_dbgClient->Release();
@ -146,7 +166,7 @@ HRESULT DbgEventCallbacks::ChangeSymbolState(
return doSymbolsLoaded(Argument); return doSymbolsLoaded(Argument);
// f.e. is case ".reload /f image.exe", if for image.exe no symbols // f.e. is case ".reload /f image.exe", if for image.exe no symbols
restoreSyntheticSymbolForAllModules(m_dbgSymbols3); restoreSyntheticSymbolForAllModules(m_dbgSymbols3, m_dbgControl);
return S_OK; return S_OK;
} }
@ -169,7 +189,7 @@ HRESULT DbgEventCallbacks::doSymbolsLoaded(
&dbgModuleParameters); &dbgModuleParameters);
if (SUCCEEDED(hres)) if (SUCCEEDED(hres))
{ {
ModuleInfo moduleInfo(dbgModuleParameters); ModuleInfo moduleInfo(dbgModuleParameters, m_dbgControl);
restoreSyntheticSymbolForModule(moduleInfo, m_dbgSymbols3); restoreSyntheticSymbolForModule(moduleInfo, m_dbgSymbols3);
} }
} }

View File

@ -45,11 +45,13 @@ private:
IDebugClient *m_dbgClient; IDebugClient *m_dbgClient;
IDebugSymbols3 *m_dbgSymbols3; IDebugSymbols3 *m_dbgSymbols3;
IDebugControl *m_dbgControl;
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
// global singleton // global singleton
static DbgEventCallbacks *dbgEventCallbacks; static DbgEventCallbacks *dbgEventCallbacks;
static volatile LONG dbgEventCallbacksStartCount;
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
}; };

View File

@ -52,14 +52,14 @@ loadMemory( ULONG64 address, PVOID dest, ULONG length, BOOLEAN phyAddr )
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
ULONG64 ULONG64
addr64( ULONG64 addr ) addr64Ex( ULONG64 addr, IDebugControl *control )
{ {
HRESULT hres; HRESULT hres;
try { try {
ULONG processorMode; ULONG processorMode;
hres = dbgExt->control->GetActualProcessorType( &processorMode ); hres = control->GetActualProcessorType( &processorMode );
if ( FAILED( hres ) ) if ( FAILED( hres ) )
throw DbgException( "IDebugControl::GetEffectiveProcessorType failed" ); throw DbgException( "IDebugControl::GetEffectiveProcessorType failed" );
@ -91,6 +91,13 @@ addr64( ULONG64 addr )
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
ULONG64 addr64( ULONG64 addr )
{
return addr64Ex(addr, dbgExt->control);
}
///////////////////////////////////////////////////////////////////////////////////
bool bool
compareMemory( ULONG64 addr1, ULONG64 addr2, ULONG length, BOOLEAN phyAddr ) compareMemory( ULONG64 addr1, ULONG64 addr2, ULONG length, BOOLEAN phyAddr )
{ {

View File

@ -79,6 +79,9 @@ loadWStrToBuffer( ULONG64 address, PWCHAR buffer, ULONG bufferLen );
bool bool
compareMemory( ULONG64 addr1, ULONG64 addr2, ULONG length, BOOLEAN phyAddr = FALSE ); compareMemory( ULONG64 addr1, ULONG64 addr2, ULONG length, BOOLEAN phyAddr = FALSE );
ULONG64
addr64Ex( ULONG64 addr, IDebugControl *control );
ULONG64 ULONG64
addr64( ULONG64 addr ); addr64( ULONG64 addr );

View File

@ -27,15 +27,17 @@ struct ModuleInfo
{ {
} }
ModuleInfo( ModuleInfo(
const IMAGEHLP_MODULEW64 &dbgImageHelperInfo const IMAGEHLP_MODULEW64 &dbgImageHelperInfo,
IDebugControl *control = dbgExt->control
) : m_base(addr64(dbgImageHelperInfo.BaseOfImage)) ) : m_base(addr64(dbgImageHelperInfo.BaseOfImage))
, m_timeDataStamp(dbgImageHelperInfo.TimeDateStamp) , m_timeDataStamp(dbgImageHelperInfo.TimeDateStamp)
, m_checkSumm(dbgImageHelperInfo.CheckSum) , m_checkSumm(dbgImageHelperInfo.CheckSum)
{ {
} }
ModuleInfo( ModuleInfo(
const DEBUG_MODULE_PARAMETERS &dbgModuleParameters const DEBUG_MODULE_PARAMETERS &dbgModuleParameters,
) : m_base(addr64(dbgModuleParameters.Base)) IDebugControl *control = dbgExt->control
) : m_base(addr64Ex(dbgModuleParameters.Base, control))
, m_timeDataStamp(dbgModuleParameters.TimeDateStamp) , m_timeDataStamp(dbgModuleParameters.TimeDateStamp)
, m_checkSumm(dbgModuleParameters.Checksum) , m_checkSumm(dbgModuleParameters.Checksum)
{ {

View File

@ -615,7 +615,8 @@ void restoreSyntheticSymbolForModule(
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
void restoreSyntheticSymbolForAllModules( void restoreSyntheticSymbolForAllModules(
IDebugSymbols3 *symbols3 IDebugSymbols3 *symbols3,
IDebugControl *control
) )
{ {
try try
@ -642,7 +643,7 @@ void restoreSyntheticSymbolForAllModules(
{ {
for (ULONG i = 0; i < arrModules.size(); ++i) for (ULONG i = 0; i < arrModules.size(); ++i)
{ {
ModuleInfo moduleInfo(arrModules[i]); ModuleInfo moduleInfo(arrModules[i], control);
restoreSyntheticSymbolForModuleNoLock(moduleInfo, symbols3); restoreSyntheticSymbolForModuleNoLock(moduleInfo, symbols3);
} }
} }

View File

@ -54,7 +54,8 @@ void restoreSyntheticSymbolForModule(
); );
void restoreSyntheticSymbolForAllModules( void restoreSyntheticSymbolForAllModules(
IDebugSymbols3 *symbols3 IDebugSymbols3 *symbols3,
IDebugControl *control
); );
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////