mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-20 03:23:23 +08:00
[pykd_ext_2.0] fixed : issue #14058, 14060, 14061
git-svn-id: https://pykd.svn.codeplex.com/svn@91172 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
parent
7783c01228
commit
ad9a59f3b0
@ -26,7 +26,7 @@ public:
|
|||||||
AutoRestorePyState pystate;
|
AutoRestorePyState pystate;
|
||||||
|
|
||||||
m_control->ControlledOutputWide(
|
m_control->ControlledOutputWide(
|
||||||
DEBUG_OUTCTL_THIS_CLIENT,
|
DEBUG_OUTCTL_ALL_CLIENTS,
|
||||||
DEBUG_OUTPUT_NORMAL,
|
DEBUG_OUTPUT_NORMAL,
|
||||||
L"%ws",
|
L"%ws",
|
||||||
str.c_str()
|
str.c_str()
|
||||||
@ -39,7 +39,7 @@ public:
|
|||||||
AutoRestorePyState pystate;
|
AutoRestorePyState pystate;
|
||||||
|
|
||||||
m_control->ControlledOutputWide(
|
m_control->ControlledOutputWide(
|
||||||
DEBUG_OUTCTL_THIS_CLIENT | DEBUG_OUTCTL_DML,
|
DEBUG_OUTCTL_ALL_CLIENTS | DEBUG_OUTCTL_DML,
|
||||||
DEBUG_OUTPUT_NORMAL,
|
DEBUG_OUTPUT_NORMAL,
|
||||||
L"%ws",
|
L"%ws",
|
||||||
str.c_str()
|
str.c_str()
|
||||||
|
@ -5,3 +5,4 @@ EXPORTS
|
|||||||
info
|
info
|
||||||
pip
|
pip
|
||||||
help
|
help
|
||||||
|
select = selectVersion
|
||||||
|
@ -157,10 +157,7 @@ public:
|
|||||||
|
|
||||||
m_module->PyImport_Cleanup();
|
m_module->PyImport_Cleanup();
|
||||||
|
|
||||||
while (PyGC_Collect() > 0);
|
|
||||||
|
|
||||||
m_module->Py_EndInterpreter(m_state);
|
m_module->Py_EndInterpreter(m_state);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PyModule* m_module;
|
PyModule* m_module;
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
#define PYKDEXT_VERSION_MAJOR 2
|
#define PYKDEXT_VERSION_MAJOR 2
|
||||||
#define PYKDEXT_VERSION_MINOR 0
|
#define PYKDEXT_VERSION_MINOR 0
|
||||||
#define PYKDEXT_VERSION_SUBVERSION 0
|
#define PYKDEXT_VERSION_SUBVERSION 0
|
||||||
#define PYKDEXT_VERSION_BUILDNO 6
|
#define PYKDEXT_VERSION_BUILDNO 8
|
||||||
|
|
||||||
#define __VER_STR2__(x) #x
|
#define __VER_STR2__(x) #x
|
||||||
#define __VER_STR1__(x) __VER_STR2__(x)
|
#define __VER_STR1__(x) __VER_STR2__(x)
|
||||||
|
@ -15,6 +15,10 @@
|
|||||||
#include "pyclass.h"
|
#include "pyclass.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
static int defaultMajorVersion = 2;
|
||||||
|
static int defaultMinorVersion = 7;
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@ -199,6 +203,32 @@ info(
|
|||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
HRESULT
|
||||||
|
CALLBACK
|
||||||
|
selectVersion(
|
||||||
|
PDEBUG_CLIENT client,
|
||||||
|
PCSTR args
|
||||||
|
)
|
||||||
|
{
|
||||||
|
Options opts(args);
|
||||||
|
|
||||||
|
int majorVersion = opts.pyMajorVersion;
|
||||||
|
int minorVersion = opts.pyMinorVersion;
|
||||||
|
|
||||||
|
getPythonVersion(majorVersion, minorVersion);
|
||||||
|
|
||||||
|
if ( opts.pyMajorVersion == majorVersion && opts.pyMinorVersion == minorVersion )
|
||||||
|
{
|
||||||
|
defaultMajorVersion = majorVersion;
|
||||||
|
defaultMinorVersion = minorVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
return S_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
static const char printUsageMsg[] =
|
static const char printUsageMsg[] =
|
||||||
"\n"
|
"\n"
|
||||||
"usage:\n"
|
"usage:\n"
|
||||||
@ -209,6 +239,9 @@ static const char printUsageMsg[] =
|
|||||||
"!info\n"
|
"!info\n"
|
||||||
"\tlist installed python interpreters\n"
|
"\tlist installed python interpreters\n"
|
||||||
"\n"
|
"\n"
|
||||||
|
"!select version\n"
|
||||||
|
"\tchange default version of a python interpreter\n"
|
||||||
|
"\n"
|
||||||
"!py [version] [options] [file]\n"
|
"!py [version] [options] [file]\n"
|
||||||
"\trun python script or REPL\n"
|
"\trun python script or REPL\n"
|
||||||
"\n"
|
"\n"
|
||||||
@ -270,6 +303,8 @@ help(
|
|||||||
|
|
||||||
static const std::regex shebangRe("^#!\\s*python([2,3])(?:\\.(\\d))?$");
|
static const std::regex shebangRe("^#!\\s*python([2,3])(?:\\.(\\d))?$");
|
||||||
|
|
||||||
|
static volatile long recursiveGuard = 0L;
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
HRESULT
|
HRESULT
|
||||||
CALLBACK
|
CALLBACK
|
||||||
@ -278,12 +313,16 @@ py(
|
|||||||
PCSTR args
|
PCSTR args
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
|
||||||
ULONG oldMask;
|
ULONG oldMask;
|
||||||
client->GetOutputMask(&oldMask);
|
client->GetOutputMask(&oldMask);
|
||||||
client->SetOutputMask(DEBUG_OUTPUT_NORMAL | DEBUG_OUTPUT_ERROR);
|
client->SetOutputMask(DEBUG_OUTPUT_NORMAL|DEBUG_OUTPUT_ERROR|DEBUG_OUTPUT_WARNING|DEBUG_OUTPUT_DEBUGGEE );
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
if ( 1 < ++recursiveGuard )
|
||||||
|
throw std::exception( "can not run !py command recursive\n");
|
||||||
|
|
||||||
Options opts(args);
|
Options opts(args);
|
||||||
|
|
||||||
if (opts.showHelp)
|
if (opts.showHelp)
|
||||||
@ -296,6 +335,9 @@ py(
|
|||||||
{
|
{
|
||||||
std::ifstream scriptFile(opts.args[0]);
|
std::ifstream scriptFile(opts.args[0]);
|
||||||
|
|
||||||
|
if ( scriptFile.is_open() )
|
||||||
|
{
|
||||||
|
|
||||||
std::string firstline;
|
std::string firstline;
|
||||||
std::getline(scriptFile, firstline);
|
std::getline(scriptFile, firstline);
|
||||||
|
|
||||||
@ -310,6 +352,7 @@ py(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
getPythonVersion(majorVersion, minorVersion);
|
getPythonVersion(majorVersion, minorVersion);
|
||||||
|
|
||||||
@ -376,7 +419,7 @@ py(
|
|||||||
|
|
||||||
PySys_SetArgv((int)opts.args.size(), &pythonArgs[0]);
|
PySys_SetArgv((int)opts.args.size(), &pythonArgs[0]);
|
||||||
|
|
||||||
PyObjectRef pyfile = PyFile_FromString(pythonArgs[0], "r");
|
PyObjectRef pyfile = PyFile_FromString(const_cast<char*>(scriptFileName.c_str()), "r");
|
||||||
if (!pyfile)
|
if (!pyfile)
|
||||||
throw std::invalid_argument("script not found\n");
|
throw std::invalid_argument("script not found\n");
|
||||||
|
|
||||||
@ -396,7 +439,7 @@ py(
|
|||||||
CComQIPtr<IDebugControl> control = client;
|
CComQIPtr<IDebugControl> control = client;
|
||||||
|
|
||||||
control->ControlledOutput(
|
control->ControlledOutput(
|
||||||
DEBUG_OUTCTL_THIS_CLIENT,
|
DEBUG_OUTCTL_ALL_CLIENTS,
|
||||||
DEBUG_OUTPUT_ERROR,
|
DEBUG_OUTPUT_ERROR,
|
||||||
e.what()
|
e.what()
|
||||||
);
|
);
|
||||||
@ -404,6 +447,8 @@ py(
|
|||||||
|
|
||||||
client->SetOutputMask(oldMask);
|
client->SetOutputMask(oldMask);
|
||||||
|
|
||||||
|
--recursiveGuard;
|
||||||
|
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -420,6 +465,9 @@ pip(
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
if ( 1 < ++recursiveGuard )
|
||||||
|
throw std::exception( "can not run !pip command recursive\n");
|
||||||
|
|
||||||
Options opts(args);
|
Options opts(args);
|
||||||
|
|
||||||
int majorVersion = opts.pyMajorVersion;
|
int majorVersion = opts.pyMajorVersion;
|
||||||
@ -461,12 +509,14 @@ pip(
|
|||||||
CComQIPtr<IDebugControl> control = client;
|
CComQIPtr<IDebugControl> control = client;
|
||||||
|
|
||||||
control->ControlledOutput(
|
control->ControlledOutput(
|
||||||
DEBUG_OUTCTL_THIS_CLIENT,
|
DEBUG_OUTCTL_ALL_CLIENTS,
|
||||||
DEBUG_OUTPUT_ERROR,
|
DEBUG_OUTPUT_ERROR,
|
||||||
e.what()
|
e.what()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
--recursiveGuard;
|
||||||
|
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -634,6 +684,8 @@ void getPythonVersion(int& majorVersion, int& minorVersion)
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void getDefaultPythonVersion(int& majorVersion, int& minorVersion)
|
void getDefaultPythonVersion(int& majorVersion, int& minorVersion)
|
||||||
{
|
{
|
||||||
std::list<InterpreterDesc> interpreterList = getInstalledInterpreter();
|
std::list<InterpreterDesc> interpreterList = getInstalledInterpreter();
|
||||||
@ -644,31 +696,20 @@ void getDefaultPythonVersion(int& majorVersion, int& minorVersion)
|
|||||||
|
|
||||||
for (auto interpret : interpreterList)
|
for (auto interpret : interpreterList)
|
||||||
{
|
{
|
||||||
if (2 == interpret.majorVersion && 7 == interpret.minorVersion)
|
if (defaultMajorVersion == interpret.majorVersion && defaultMinorVersion == interpret.minorVersion)
|
||||||
{
|
{
|
||||||
majorVersion = 2;
|
majorVersion = defaultMajorVersion;
|
||||||
minorVersion = 7;
|
minorVersion = defaultMinorVersion;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto interpret : interpreterList)
|
for (auto interpret : interpreterList)
|
||||||
{
|
{
|
||||||
if (3 == interpret.majorVersion && 5 == interpret.minorVersion)
|
if (2 == interpret.majorVersion && minorVersion <= interpret.minorVersion )
|
||||||
{
|
|
||||||
majorVersion = 3;
|
|
||||||
minorVersion = 5;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto interpret : interpreterList)
|
|
||||||
{
|
|
||||||
if (2 == interpret.majorVersion &&
|
|
||||||
minorVersion <= interpret.minorVersion )
|
|
||||||
{
|
{
|
||||||
found = true;
|
found = true;
|
||||||
majorVersion = 2;
|
majorVersion = interpret.majorVersion;
|
||||||
minorVersion = interpret.minorVersion;
|
minorVersion = interpret.minorVersion;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -678,11 +719,10 @@ void getDefaultPythonVersion(int& majorVersion, int& minorVersion)
|
|||||||
|
|
||||||
for (auto interpret : interpreterList)
|
for (auto interpret : interpreterList)
|
||||||
{
|
{
|
||||||
if (3 == interpret.majorVersion &&
|
if (3 == interpret.majorVersion && minorVersion <= interpret.minorVersion )
|
||||||
minorVersion <= interpret.minorVersion )
|
|
||||||
{
|
{
|
||||||
found = true;
|
found = true;
|
||||||
majorVersion = 3;
|
majorVersion = interpret.majorVersion;
|
||||||
minorVersion = interpret.minorVersion;
|
minorVersion = interpret.minorVersion;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user