From 30d291750a875e471846a2bd79974f2933ca79e3 Mon Sep 17 00:00:00 2001 From: "SND\\kernelnet_cp" Date: Wed, 13 Apr 2011 07:28:56 +0000 Subject: [PATCH] [pykd] fixed: issue 8499 ( !py command crashs with wrong script's path ) git-svn-id: https://pykd.svn.codeplex.com/svn@63927 9b283d60-5439-405e-af05-b73fd8c4d996 --- pykd/dbgext.cpp | 18 ++++-------------- pykd/dbgpath.cpp | 28 +++++++++++++++++----------- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/pykd/dbgext.cpp b/pykd/dbgext.cpp index 0bb097f..86adc28 100644 --- a/pykd/dbgext.cpp +++ b/pykd/dbgext.cpp @@ -566,22 +566,14 @@ py( PDEBUG_CLIENT4 client, PCSTR args) std::string filePath; DbgPythonPath dbgPythonPath; + if ( dbgPythonPath.findPath( argsList[0], fullFileName, filePath ) ) { - DWORD oldCurDirLen = GetCurrentDirectoryA( 0, NULL ); - - std::vector oldCurDirCstr(oldCurDirLen); - - GetCurrentDirectoryA( oldCurDirLen, &oldCurDirCstr[0] ); - - // SetCurrentDirectoryA( filePath.c_str() ); - - try { - + try { + boost::python::object result; result = boost::python::exec_file( fullFileName.c_str(), global, global ); - } catch( boost::python::error_already_set const & ) { @@ -603,13 +595,11 @@ py( PDEBUG_CLIENT4 client, PCSTR args) Py_XDECREF(errtype); Py_XDECREF(traceback); } - - SetCurrentDirectoryA( &oldCurDirCstr[0] ); } else { dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "script file not found\n" ); - } + } } catch(...) diff --git a/pykd/dbgpath.cpp b/pykd/dbgpath.cpp index e2ea4d2..51b6379 100644 --- a/pykd/dbgpath.cpp +++ b/pykd/dbgpath.cpp @@ -86,6 +86,7 @@ DbgPythonPath::findPath( if ( bufSize > 0 ) { + bufSize += 1; std::vector fullFileNameCStr(bufSize); char *partFileNameCStr = NULL; @@ -95,12 +96,14 @@ DbgPythonPath::findPath( pyExt ? NULL : ".py", bufSize, &fullFileNameCStr[0], - &partFileNameCStr ); + &partFileNameCStr ); fullFileName = std::string( &fullFileNameCStr[0] ); - filePath = std::string( &fullFileNameCStr[0], partFileNameCStr ); - - return true; + if ( !fullFileName.empty() ) + { + filePath = std::string( &fullFileNameCStr[0], partFileNameCStr ); + return true; + } } // 2. Ищем во всех директориях, указанных в m_pathList @@ -120,21 +123,24 @@ DbgPythonPath::findPath( if ( bufSize > 0 ) { + bufSize += 1; std::vector fullFileNameCStr(bufSize); char *partFileNameCStr = NULL; - SearchPathA( + bufSize = SearchPathA( (*it).c_str(), fileName.c_str(), pyExt ? NULL : ".py", bufSize, &fullFileNameCStr[0], - &partFileNameCStr ); - - fullFileName = std::string( &fullFileNameCStr[0] ); - filePath = std::string( &fullFileNameCStr[0], partFileNameCStr ); - - return true; + &partFileNameCStr ); + + fullFileName = std::string( &fullFileNameCStr[0] ); + if ( !fullFileName.empty() ) + { + filePath = std::string( &fullFileNameCStr[0], partFileNameCStr ); + return true; + } } }