From 04e70471dc1dd0efc90514a6033677bcaef31464 Mon Sep 17 00:00:00 2001
From: "SND\\kernelnet_cp"
 <SND\kernelnet_cp@9b283d60-5439-405e-af05-b73fd8c4d996>
Date: Thu, 31 Oct 2013 08:18:35 +0000
Subject: [PATCH] [0.3.x] added : startProcess extra parameter debugChildren

git-svn-id: https://pykd.svn.codeplex.com/svn@86121 9b283d60-5439-405e-af05-b73fd8c4d996
---
 pykd/dbgengine.cpp        |  4 ++--
 pykd/dbgengine.h          |  2 +-
 pykd/pymod.cpp            |  6 ++++--
 test/scripts/stacktest.py | 32 ++++++++++++++++++++++++++++++++
 4 files changed, 39 insertions(+), 5 deletions(-)
 create mode 100644 test/scripts/stacktest.py

diff --git a/pykd/dbgengine.cpp b/pykd/dbgengine.cpp
index 0992454..9a6c073 100644
--- a/pykd/dbgengine.cpp
+++ b/pykd/dbgengine.cpp
@@ -60,13 +60,13 @@ kdlib::ExecutionStatus targetStepIn()
 
 ///////////////////////////////////////////////////////////////////////////////
 
-kdlib::PROCESS_DEBUG_ID startProcess( const std::wstring  &processName )
+kdlib::PROCESS_DEBUG_ID startProcess( const std::wstring  &processName, bool debugChildren )
 {
     kdlib::PROCESS_DEBUG_ID  id;
 
     AutoRestorePyState  pystate;
 
-    id = kdlib::startProcess(processName);
+    id = kdlib::startProcess(processName, debugChildren);
 
     return id;
 }
diff --git a/pykd/dbgengine.h b/pykd/dbgengine.h
index e53f956..e4d29a0 100644
--- a/pykd/dbgengine.h
+++ b/pykd/dbgengine.h
@@ -14,7 +14,7 @@ void targetBreak();
 kdlib::ExecutionStatus targetStep();
 kdlib::ExecutionStatus targetStepIn();
 
-kdlib::PROCESS_DEBUG_ID startProcess( const std::wstring  &processName );
+kdlib::PROCESS_DEBUG_ID startProcess( const std::wstring  &processName, bool debugChildren = false );
 kdlib::PROCESS_DEBUG_ID attachProcess( kdlib::PROCESS_ID pid );
 void loadDump( const std::wstring &fileName );
 
diff --git a/pykd/pymod.cpp b/pykd/pymod.cpp
index dc87732..d59b08d 100644
--- a/pykd/pymod.cpp
+++ b/pykd/pymod.cpp
@@ -29,6 +29,8 @@ static const std::string pykdVersion = PYKD_VERSION_BUILD_STR
 
 ///////////////////////////////////////////////////////////////////////////////
 
+
+BOOST_PYTHON_FUNCTION_OVERLOADS( startProcess_,  startProcess, 1, 2 );
 BOOST_PYTHON_FUNCTION_OVERLOADS( detachProcess_,  kdlib::detachProcess, 0, 1 );
 BOOST_PYTHON_FUNCTION_OVERLOADS( terminateProcess_,  kdlib::terminateProcess, 0, 1 );
 BOOST_PYTHON_FUNCTION_OVERLOADS( attachKernel_,  attachKernel, 0, 1 );
@@ -87,8 +89,8 @@ BOOST_PYTHON_MODULE( pykd )
 
    // Manage debug target 
 
-    python::def( "startProcess", &startProcess,
-        "Start process for debugging" ); 
+    python::def( "startProcess", &startProcess, startProcess_( boost::python::args( "commandline", "debugChildren" ), 
+        "Start process for debugging" ) ); 
     python::def( "attachProcess", &attachProcess,
         "Attach debugger to a exsisting process" );
     python::def( "detachProcess", &kdlib::detachProcess, detachProcess_( boost::python::args( "pid" ),
diff --git a/test/scripts/stacktest.py b/test/scripts/stacktest.py
new file mode 100644
index 0000000..7e37169
--- /dev/null
+++ b/test/scripts/stacktest.py
@@ -0,0 +1,32 @@
+import unittest
+import pykd
+import target
+
+class StackTest(unittest.TestCase):
+    
+    def setUp(self):
+        self.processId = pykd.startProcess( target.appPath + " stacktest" )
+        pykd.go() # skip initial breakpoint
+
+    def tearDown(self):
+        pykd.killProcess( self.processId )
+
+    def testGetStack(self):
+
+        expectedStack = [ 'targetapp!stackTestRun2',
+                  'targetapp!stackTestRun1',
+                  'targetapp!stackTestRun',
+                  'targetapp!wmain',
+                  'targetapp!__tmainCRTStartup',
+                  'targetapp!wmainCRTStartup',
+                  'kernel32!BaseThreadInitThunk',
+                  'ntdll!RtlUserThreadStart' ]
+
+        realStack = []
+        for frame in pykd.getStack():
+            moduleName, symbolName, disp = pykd.findSymbolAndDisp( frame.ip )
+            realStack.append( "%s!%s" % ( moduleName, symbolName ) )
+
+        self.assertEqual( expectedStack, realStack )
+
+