2011-09-15 22:16:20 +08:00
|
|
|
#include "stdafx.h"
|
|
|
|
|
|
|
|
#include "dbgclient.h"
|
|
|
|
#include <vector>
|
|
|
|
|
2011-09-21 23:53:02 +08:00
|
|
|
|
|
|
|
namespace pykd {
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-10-10 19:28:00 +08:00
|
|
|
DebugClientPtr g_dbgClient( DebugClient::createDbgClient() );
|
2011-09-21 23:53:02 +08:00
|
|
|
|
|
|
|
void loadDump( const std::wstring &fileName ) {
|
|
|
|
g_dbgClient->loadDump( fileName );
|
|
|
|
}
|
|
|
|
|
|
|
|
void startProcess( const std::wstring &processName ) {
|
|
|
|
g_dbgClient->startProcess( processName );
|
|
|
|
}
|
|
|
|
|
|
|
|
void attachProcess( ULONG processId ) {
|
|
|
|
g_dbgClient->attachProcess( processId );
|
|
|
|
}
|
|
|
|
|
|
|
|
void attachKernel( const std::wstring ¶m ) {
|
|
|
|
g_dbgClient->attachKernel( param );
|
|
|
|
}
|
2011-09-15 22:16:20 +08:00
|
|
|
|
2011-10-03 15:40:27 +08:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
DebugClientPtr DebugClient::setDbgClientCurrent( DebugClientPtr newDbgClient ) {
|
|
|
|
DebugClientPtr oldClient = g_dbgClient;
|
|
|
|
g_dbgClient = newDbgClient;
|
|
|
|
return oldClient;
|
|
|
|
}
|
|
|
|
|
2011-09-15 22:16:20 +08:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void DebugClient::loadDump( const std::wstring &fileName )
|
|
|
|
{
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = m_client->OpenDumpFileWide( fileName.c_str(), NULL );
|
|
|
|
if ( FAILED( hres ) )
|
|
|
|
throw DbgException( "IDebugClient4::OpenDumpFileWide failed" );
|
|
|
|
|
|
|
|
hres = m_control->WaitForEvent(DEBUG_WAIT_DEFAULT, INFINITE);
|
|
|
|
if ( FAILED( hres ) )
|
|
|
|
throw DbgException( "IDebugControl::WaitForEvent failed" );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void DebugClient::startProcess( const std::wstring &processName )
|
|
|
|
{
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
ULONG opt;
|
|
|
|
hres = m_control->GetEngineOptions( &opt );
|
|
|
|
if ( FAILED( hres ) )
|
|
|
|
throw DbgException( "IDebugControl::GetEngineOptions failed" );
|
|
|
|
|
|
|
|
opt |= DEBUG_ENGOPT_INITIAL_BREAK;
|
|
|
|
hres = m_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 = m_client->CreateProcessWide( 0, &cmdLine[0], DEBUG_PROCESS | DETACHED_PROCESS );
|
|
|
|
if ( FAILED( hres ) )
|
|
|
|
throw DbgException( "IDebugClient4::CreateProcessWide failed" );
|
|
|
|
|
|
|
|
hres = m_control->WaitForEvent(DEBUG_WAIT_DEFAULT, INFINITE);
|
|
|
|
if ( FAILED( hres ) )
|
|
|
|
throw DbgException( "IDebugControl::WaitForEvent failed" );
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void DebugClient::attachProcess( ULONG processId )
|
|
|
|
{
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = m_client->AttachProcess( 0, processId, 0 );
|
|
|
|
if ( FAILED( hres ) )
|
|
|
|
throw DbgException( "IDebugClient::AttachProcess failed" );
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void DebugClient::attachKernel( const std::wstring ¶m )
|
|
|
|
{
|
|
|
|
HRESULT hres;
|
|
|
|
|
2011-10-10 19:19:12 +08:00
|
|
|
hres = m_client5->AttachKernelWide( DEBUG_ATTACH_KERNEL_CONNECTION, param.c_str() );
|
2011-09-15 22:16:20 +08:00
|
|
|
if ( FAILED( hres ) )
|
|
|
|
throw DbgException( "IDebugClient5::AttachKernelWide failed" );
|
|
|
|
}
|
|
|
|
|
2011-09-21 23:53:02 +08:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
}; // end of namespace pykd
|