From b84b298ea7a2395c9caa9248e16c2ef7d47eccf7 Mon Sep 17 00:00:00 2001 From: "SND\\kernelnet_cp" Date: Wed, 2 Mar 2011 08:40:33 +0000 Subject: [PATCH] [+] added: startProcess routine for live user-mode debugging [~] updated: createSession routine is depricated now [~] updated: loadDump routine returns bool now ( not string ) git-svn-id: https://pykd.svn.codeplex.com/svn@62085 9b283d60-5439-405e-af05-b73fd8c4d996 --- pykd/dbgdump.cpp | 89 ++++++++++++++++++++++++++++++++------------- pykd/dbgdump.h | 7 +++- pykd/dbgext.cpp | 3 +- pykd/dbgsession.cpp | 2 + 4 files changed, 72 insertions(+), 29 deletions(-) diff --git a/pykd/dbgdump.cpp b/pykd/dbgdump.cpp index a57c9a2..0fddd84 100644 --- a/pykd/dbgdump.cpp +++ b/pykd/dbgdump.cpp @@ -7,51 +7,88 @@ #include "dbgexcept.h" #include "dbgsession.h" #include "dbgsystem.h" +#include "dbgcmd.h" ///////////////////////////////////////////////////////////////////////////////// -std::string -dbgLoadDump( const std::string &fileName ) +bool +dbgLoadDump( const std::wstring &fileName ) { HRESULT hres; try { - - std::vector fileNameW( fileName.size()+ 1 ); - - MultiByteToWideChar( - CP_ACP, - 0, - fileName.c_str(), - fileName.size() + 1, - &fileNameW[0], - fileName.size() + 1 ); - - hres = dbgExt->client4->OpenDumpFileWide( &fileNameW[0], NULL ); + + if ( !dbgSessionStarted ) + dbgCreateSession(); + + 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" ); - - dbgSessionStarted = true; + throw DbgException( "IDebugControl::WaitForEvent failed" ); - return "loaded ok"; + return true; } catch( std::exception& ) { - //g_Ext->Out( "pykd error: %s\n", e.what() ); + } catch(...) { - //g_Ext->Out( "pykd unexpected error\n" ); - } - - std::string result = "failed to open dump "; - result += fileName; - - return result; + dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" ); + } + + return false; } +///////////////////////////////////////////////////////////////////////////////// + +bool +startProcess( const std::wstring &processName ) +{ + HRESULT hres; + + try { + + if ( !dbgSessionStarted ) + dbgCreateSession(); + + 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" ); + + 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; +} + ///////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/pykd/dbgdump.h b/pykd/dbgdump.h index 8c5f898..4cc6524 100644 --- a/pykd/dbgdump.h +++ b/pykd/dbgdump.h @@ -4,7 +4,10 @@ ///////////////////////////////////////////////////////////////////////////////// -std::string -dbgLoadDump( const std::string &dumpName ); +bool +dbgLoadDump( const std::wstring &dumpName ); + +bool +startProcess( const std::wstring &processName ); ///////////////////////////////////////////////////////////////////////////////// diff --git a/pykd/dbgext.cpp b/pykd/dbgext.cpp index 8a9a5e2..23aad65 100644 --- a/pykd/dbgext.cpp +++ b/pykd/dbgext.cpp @@ -91,12 +91,13 @@ BOOST_PYTHON_MODULE( pykd ) boost::python::def( "trace", &setExecutionStatus ); boost::python::def( "step", &setExecutionStatus ); boost::python::def( "expr", &evaluate ); - boost::python::def( "createSession", &dbgCreateSession ); + boost::python::def( "createSession", &dbgCreateSession ); // depricated boost::python::def( "isSessionStart", &dbgIsSessionStart ); boost::python::def( "symbolsPath", &dbgSymPath ); boost::python::def( "dprint", &DbgPrint::dprint, dprint( boost::python::args( "str", "dml" ), "" ) ); boost::python::def( "dprintln", &DbgPrint::dprintln, dprintln( boost::python::args( "str", "dml" ), "" ) ); boost::python::def( "loadDump", &dbgLoadDump ); + boost::python::def( "startProcess", &startProcess ); boost::python::def( "dbgCommand", &dbgCommand ); boost::python::def( "isValid", &isOffsetValid ); boost::python::def( "is64bitSystem", &is64bitSystem ); diff --git a/pykd/dbgsession.cpp b/pykd/dbgsession.cpp index 0107325..11ccbc9 100644 --- a/pykd/dbgsession.cpp +++ b/pykd/dbgsession.cpp @@ -16,6 +16,8 @@ dbgCreateSession() SetupDebugEngine( client, &dbgGlobalSession ); dbgExt = &dbgGlobalSession; + dbgExt->control->Output( DEBUG_OUTPUT_WARNING, "Depricated call\n" ); + dbgSessionStarted = true; }