From b720184b4e4344a6b053a835c681069435cef290 Mon Sep 17 00:00:00 2001
From: "SND\\EreTIk_cp" <SND\EreTIk_cp@9b283d60-5439-405e-af05-b73fd8c4d996>
Date: Wed, 2 Mar 2011 13:56:22 +0000
Subject: [PATCH] [!] restored revisions: 62086 and 62085

git-svn-id: https://pykd.svn.codeplex.com/svn@62092 9b283d60-5439-405e-af05-b73fd8c4d996
---
 pykd/dbgdump.cpp | 97 +++++++++++++++++++++++++++++++++---------------
 pykd/dbgdump.h   |  7 +++-
 pykd/dbgext.cpp  |  3 +-
 3 files changed, 74 insertions(+), 33 deletions(-)

diff --git a/pykd/dbgdump.cpp b/pykd/dbgdump.cpp
index a49e762..baf6da6 100644
--- a/pykd/dbgdump.cpp
+++ b/pykd/dbgdump.cpp
@@ -8,51 +8,88 @@
 #include "dbgeventcb.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<wchar_t> fileNameW( fileName.size()+ 1 );
-    
-        MultiByteToWideChar(
-            CP_ACP,            
-            0,
-            fileName.c_str(),
-            (ULONG)fileName.size() + 1,
-            &fileNameW[0],
-            (ULONG)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" );   
+            throw DbgException( "IDebugControl::WaitForEvent failed" );
 
-        setDbgSessionStarted();
-
-        return "loaded ok";
+        return true;
+    }
+    catch( std::exception& )
+    {
+    }
+    catch(...)
+    {
+        dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" );
     }
- 	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;
+    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 ac0fc15..84f1410 100644
--- a/pykd/dbgext.cpp
+++ b/pykd/dbgext.cpp
@@ -91,12 +91,13 @@ BOOST_PYTHON_MODULE( pykd )
     boost::python::def( "trace", &setExecutionStatus<DEBUG_STATUS_STEP_INTO> );
     boost::python::def( "step", &setExecutionStatus<DEBUG_STATUS_STEP_OVER> );   
     boost::python::def( "expr", &evaluate ); 
-    boost::python::def( "createSession", &dbgCreateSession );
+    boost::python::def( "createSession", &dbgCreateSession );   // deprecated
     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 );