diff --git a/pykd/dbgdump.cpp b/pykd/dbgdump.cpp index 3c333d7..e8c71bb 100644 --- a/pykd/dbgdump.cpp +++ b/pykd/dbgdump.cpp @@ -16,92 +16,76 @@ bool dbgStarted = false; ///////////////////////////////////////////////////////////////////////////////// -bool +void dbgLoadDump( const std::wstring &fileName ) { HRESULT hres; - try { + if ( dbgStarted || isWindbgExt() ) + throw DbgException( "debugger is alread attached" ); - if ( dbgStarted || isWindbgExt() ) - return false; + g_dbgClient.startEventsMgr(); + + hres = dbgExt->client4->OpenDumpFileWide( fileName.c_str(), NULL ); + + if ( FAILED( hres ) ) + throw DbgException( "IDebugClient4::OpenDumpFileWide failed" ); - g_dbgClient.startEventsMgr(); - - hres = dbgExt->client4->OpenDumpFileWide( fileName.c_str(), NULL ); - - if ( FAILED( hres ) ) - 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; + hres = dbgExt->control->WaitForEvent(DEBUG_WAIT_DEFAULT, INFINITE); + if ( FAILED( hres ) ) + throw DbgException( "IDebugControl::WaitForEvent failed" ); + + dbgStarted = true; } ///////////////////////////////////////////////////////////////////////////////// -bool +void startProcess( const std::wstring &processName ) { HRESULT hres; - - try { - if ( dbgStarted || isWindbgExt() ) - return false; + 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" ); - 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" ); - - 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; + dbgStarted = true; } +///////////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////////// \ No newline at end of file +void +attachProcess( ULONG processId ) +{ + HRESULT hres; + + hres = dbgExt->client->AttachProcess( 0, processId, 0 ); + if ( FAILED( hres ) ) + throw DbgException( "IDebugClient::AttachProcess failed" ); +} + +///////////////////////////////////////////////////////////////////////////////// + + \ No newline at end of file diff --git a/pykd/dbgdump.h b/pykd/dbgdump.h index 4cc6524..b84fcce 100644 --- a/pykd/dbgdump.h +++ b/pykd/dbgdump.h @@ -4,10 +4,13 @@ ///////////////////////////////////////////////////////////////////////////////// -bool +void dbgLoadDump( const std::wstring &dumpName ); -bool +void startProcess( const std::wstring &processName ); +void +attachProcess( ULONG processId ); + ///////////////////////////////////////////////////////////////////////////////// diff --git a/pykd/dbgext.cpp b/pykd/dbgext.cpp index 7a51348..d4b95bc 100644 --- a/pykd/dbgext.cpp +++ b/pykd/dbgext.cpp @@ -91,6 +91,8 @@ BOOST_PYTHON_MODULE( pykd ) "Load crash dump (only for console)"); boost::python::def( "startProcess", &startProcess, "Start process for debugging (only for console)"); + boost::python::def( "attachProcess", &attachProcess, + "Attach debugger to the exsisting process" ); boost::python::def( "dbgCommand", &dbgCommand, "Execute debugger command. For example: dbgCommand( \"lmvm nt\" )" ); boost::python::def( "isValid", &isOffsetValid,