mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-21 04:13:22 +08:00
[pykd] added : attachProcess routine ( attach debugger to the exsisting process )
git-svn-id: https://pykd.svn.codeplex.com/svn@69148 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
parent
d01c8d0436
commit
02b54e10da
126
pykd/dbgdump.cpp
126
pykd/dbgdump.cpp
@ -16,92 +16,76 @@ bool dbgStarted = false;
|
|||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
bool
|
void
|
||||||
dbgLoadDump( const std::wstring &fileName )
|
dbgLoadDump( const std::wstring &fileName )
|
||||||
{
|
{
|
||||||
HRESULT hres;
|
HRESULT hres;
|
||||||
|
|
||||||
try {
|
if ( dbgStarted || isWindbgExt() )
|
||||||
|
throw DbgException( "debugger is alread attached" );
|
||||||
|
|
||||||
if ( dbgStarted || isWindbgExt() )
|
g_dbgClient.startEventsMgr();
|
||||||
return false;
|
|
||||||
|
hres = dbgExt->client4->OpenDumpFileWide( fileName.c_str(), NULL );
|
||||||
|
|
||||||
|
if ( FAILED( hres ) )
|
||||||
|
throw DbgException( "IDebugClient4::OpenDumpFileWide failed" );
|
||||||
|
|
||||||
g_dbgClient.startEventsMgr();
|
hres = dbgExt->control->WaitForEvent(DEBUG_WAIT_DEFAULT, INFINITE);
|
||||||
|
if ( FAILED( hres ) )
|
||||||
hres = dbgExt->client4->OpenDumpFileWide( fileName.c_str(), NULL );
|
throw DbgException( "IDebugControl::WaitForEvent failed" );
|
||||||
|
|
||||||
if ( FAILED( hres ) )
|
dbgStarted = true;
|
||||||
throw DbgException( "IDebugClient4::OpenDumpFileWide failed" );
|
|
||||||
|
|
||||||
hres = dbgExt->control->WaitForEvent(DEBUG_WAIT_DEFAULT, INFINITE);
|
|
||||||
if ( FAILED( hres ) )
|
|
||||||
throw DbgException( "IDebugControl::WaitForEvent failed" );
|
|
||||||
|
|
||||||
dbgStarted = true;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch( std::exception& )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
catch(...)
|
|
||||||
{
|
|
||||||
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" );
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
bool
|
void
|
||||||
startProcess( const std::wstring &processName )
|
startProcess( const std::wstring &processName )
|
||||||
{
|
{
|
||||||
HRESULT hres;
|
HRESULT hres;
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
if ( dbgStarted || isWindbgExt() )
|
if ( dbgStarted || isWindbgExt() )
|
||||||
return false;
|
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" );
|
||||||
|
|
||||||
g_dbgClient.startEventsMgr();
|
dbgStarted = true;
|
||||||
|
|
||||||
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" );
|
|
||||||
|
|
||||||
dbgStarted = true;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch( std::exception& e )
|
|
||||||
{
|
|
||||||
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() );
|
|
||||||
}
|
|
||||||
catch(...)
|
|
||||||
{
|
|
||||||
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" );
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
void
|
||||||
|
attachProcess( ULONG processId )
|
||||||
|
{
|
||||||
|
HRESULT hres;
|
||||||
|
|
||||||
|
hres = dbgExt->client->AttachProcess( 0, processId, 0 );
|
||||||
|
if ( FAILED( hres ) )
|
||||||
|
throw DbgException( "IDebugClient::AttachProcess failed" );
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
@ -4,10 +4,13 @@
|
|||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
bool
|
void
|
||||||
dbgLoadDump( const std::wstring &dumpName );
|
dbgLoadDump( const std::wstring &dumpName );
|
||||||
|
|
||||||
bool
|
void
|
||||||
startProcess( const std::wstring &processName );
|
startProcess( const std::wstring &processName );
|
||||||
|
|
||||||
|
void
|
||||||
|
attachProcess( ULONG processId );
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -91,6 +91,8 @@ BOOST_PYTHON_MODULE( pykd )
|
|||||||
"Load crash dump (only for console)");
|
"Load crash dump (only for console)");
|
||||||
boost::python::def( "startProcess", &startProcess,
|
boost::python::def( "startProcess", &startProcess,
|
||||||
"Start process for debugging (only for console)");
|
"Start process for debugging (only for console)");
|
||||||
|
boost::python::def( "attachProcess", &attachProcess,
|
||||||
|
"Attach debugger to the exsisting process" );
|
||||||
boost::python::def( "dbgCommand", &dbgCommand,
|
boost::python::def( "dbgCommand", &dbgCommand,
|
||||||
"Execute debugger command. For example: dbgCommand( \"lmvm nt\" )" );
|
"Execute debugger command. For example: dbgCommand( \"lmvm nt\" )" );
|
||||||
boost::python::def( "isValid", &isOffsetValid,
|
boost::python::def( "isValid", &isOffsetValid,
|
||||||
|
Loading…
Reference in New Issue
Block a user