2010-07-26 18:55:12 +08:00
|
|
|
#include "stdafx.h"
|
|
|
|
|
|
|
|
#include "dbgext.h"
|
|
|
|
#include "dbgdump.h"
|
|
|
|
#include "dbgexcept.h"
|
2011-03-02 21:16:42 +08:00
|
|
|
#include "dbgeventcb.h"
|
2010-07-26 18:55:12 +08:00
|
|
|
#include "dbgsystem.h"
|
2011-03-02 21:56:22 +08:00
|
|
|
#include "dbgcmd.h"
|
2011-04-14 20:28:22 +08:00
|
|
|
#include "dbgclient.h"
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static
|
|
|
|
bool dbgStarted = false;
|
2010-07-26 18:55:12 +08:00
|
|
|
|
2011-04-08 15:53:37 +08:00
|
|
|
|
2010-07-26 18:55:12 +08:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-08-19 23:27:05 +08:00
|
|
|
void
|
2011-03-02 21:56:22 +08:00
|
|
|
dbgLoadDump( const std::wstring &fileName )
|
2010-07-26 18:55:12 +08:00
|
|
|
{
|
|
|
|
HRESULT hres;
|
|
|
|
|
2011-08-19 23:27:05 +08:00
|
|
|
if ( dbgStarted || isWindbgExt() )
|
|
|
|
throw DbgException( "debugger is alread attached" );
|
2011-04-14 20:28:22 +08:00
|
|
|
|
2011-08-19 23:27:05 +08:00
|
|
|
g_dbgClient.startEventsMgr();
|
|
|
|
|
|
|
|
hres = dbgExt->client4->OpenDumpFileWide( fileName.c_str(), NULL );
|
|
|
|
|
|
|
|
if ( FAILED( hres ) )
|
|
|
|
throw DbgException( "IDebugClient4::OpenDumpFileWide failed" );
|
2011-04-08 15:53:37 +08:00
|
|
|
|
2011-08-19 23:27:05 +08:00
|
|
|
hres = dbgExt->control->WaitForEvent(DEBUG_WAIT_DEFAULT, INFINITE);
|
|
|
|
if ( FAILED( hres ) )
|
|
|
|
throw DbgException( "IDebugControl::WaitForEvent failed" );
|
|
|
|
|
|
|
|
dbgStarted = true;
|
2011-03-02 21:56:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-08-19 23:27:05 +08:00
|
|
|
void
|
2011-03-02 21:56:22 +08:00
|
|
|
startProcess( const std::wstring &processName )
|
|
|
|
{
|
|
|
|
HRESULT hres;
|
2011-04-08 15:53:37 +08:00
|
|
|
|
2011-08-19 23:27:05 +08:00
|
|
|
if ( dbgStarted || isWindbgExt() )
|
|
|
|
throw DbgException( "debugger is alread attached" );
|
|
|
|
|
|
|
|
g_dbgClient.startEventsMgr();
|
|
|
|
|
|
|
|
ULONG opt;
|
|
|
|
hres = dbgExt->control->GetEngineOptions( &opt );
|
|
|
|
if ( FAILED( hres ) )
|
|
|
|
throw DbgException( "IDebugControl::GetEngineOptions failed" );
|
|
|
|
|
|
|
|
opt |= DEBUG_ENGOPT_INITIAL_BREAK;
|
|
|
|
hres = dbgExt->control->SetEngineOptions( opt );
|
|
|
|
if ( FAILED( hres ) )
|
|
|
|
throw DbgException( "IDebugControl::SetEngineOptions failed" );
|
|
|
|
|
|
|
|
std::vector< std::wstring::value_type> cmdLine( processName.size() + 1 );
|
|
|
|
wcscpy_s( &cmdLine[0], cmdLine.size(), processName.c_str() );
|
|
|
|
|
|
|
|
hres = dbgExt->client4->CreateProcessWide( 0, &cmdLine[0], DEBUG_PROCESS | DETACHED_PROCESS );
|
|
|
|
if ( FAILED( hres ) )
|
|
|
|
throw DbgException( "IDebugClient4::CreateProcessWide failed" );
|
|
|
|
|
|
|
|
hres = dbgExt->control->WaitForEvent(DEBUG_WAIT_DEFAULT, INFINITE);
|
|
|
|
if ( FAILED( hres ) )
|
|
|
|
throw DbgException( "IDebugControl::WaitForEvent failed" );
|
2011-04-14 20:28:22 +08:00
|
|
|
|
2011-08-19 23:27:05 +08:00
|
|
|
dbgStarted = true;
|
2011-03-02 21:16:42 +08:00
|
|
|
}
|
2010-07-26 18:55:12 +08:00
|
|
|
|
2011-08-19 23:27:05 +08:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void
|
|
|
|
attachProcess( ULONG processId )
|
|
|
|
{
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = dbgExt->client->AttachProcess( 0, processId, 0 );
|
|
|
|
if ( FAILED( hres ) )
|
|
|
|
throw DbgException( "IDebugClient::AttachProcess failed" );
|
|
|
|
}
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
2011-03-02 21:56:22 +08:00
|
|
|
|
2011-08-22 14:50:38 +08:00
|
|
|
void
|
|
|
|
attachKernel( const std::wstring param )
|
|
|
|
{
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = dbgExt->client5->AttachKernelWide( DEBUG_ATTACH_KERNEL_CONNECTION, param.c_str() );
|
|
|
|
if ( FAILED( hres ) )
|
|
|
|
throw DbgException( "IDebugClient5::AttachKernelWide failed" );
|
|
|
|
}
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|