mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-20 03:23:23 +08:00
[pykd_ext_2.0] added : python version can be note in the first script line ( shebang line )
git-svn-id: https://pykd.svn.codeplex.com/svn@91049 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
parent
584eb08fa7
commit
85a36df11e
@ -2,17 +2,18 @@
|
|||||||
|
|
||||||
#include <boost/tokenizer.hpp>
|
#include <boost/tokenizer.hpp>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
#include <list>
|
||||||
|
|
||||||
#include "arglist.h"
|
#include "arglist.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
typedef boost::escaped_list_separator<char> char_separator_t;
|
typedef boost::escaped_list_separator<char> char_separator_t;
|
||||||
typedef boost::tokenizer< char_separator_t > char_tokenizer_t;
|
typedef boost::tokenizer< char_separator_t > char_tokenizer_t;
|
||||||
|
|
||||||
|
ArgsList getArgsList(const std::string& argsStr)
|
||||||
ArgsList getArgsList(const char* args)
|
|
||||||
{
|
{
|
||||||
std::string argsStr(args);
|
|
||||||
|
|
||||||
char_tokenizer_t token(argsStr, char_separator_t("", " \t", "\""));
|
char_tokenizer_t token(argsStr, char_separator_t("", " \t", "\""));
|
||||||
ArgsList argsList;
|
ArgsList argsList;
|
||||||
|
|
||||||
@ -25,16 +26,19 @@ ArgsList getArgsList(const char* args)
|
|||||||
return argsList;
|
return argsList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // anonymous namespace
|
||||||
|
|
||||||
|
|
||||||
static const std::regex versionRe("^-([2,3])(?:\\.(\\d+))?$");
|
static const std::regex versionRe("^-([2,3])(?:\\.(\\d+))?$");
|
||||||
|
|
||||||
Options::Options(const ArgsList& argList) :
|
Options::Options(const std::string& cmdline) :
|
||||||
pyMajorVersion(-1),
|
pyMajorVersion(-1),
|
||||||
pyMinorVersion(-1),
|
pyMinorVersion(-1),
|
||||||
global(true),
|
global(true),
|
||||||
showHelp(false)
|
showHelp(false)
|
||||||
{
|
{
|
||||||
|
|
||||||
args = argList;
|
args = getArgsList( cmdline );
|
||||||
|
|
||||||
for (auto it = args.begin(); it != args.end();)
|
for (auto it = args.begin(); it != args.end();)
|
||||||
{
|
{
|
||||||
|
@ -5,8 +5,6 @@
|
|||||||
|
|
||||||
typedef std::vector< std::string > ArgsList;
|
typedef std::vector< std::string > ArgsList;
|
||||||
|
|
||||||
ArgsList getArgsList(const char* args);
|
|
||||||
|
|
||||||
struct Options
|
struct Options
|
||||||
{
|
{
|
||||||
int pyMajorVersion;
|
int pyMajorVersion;
|
||||||
@ -22,6 +20,5 @@ struct Options
|
|||||||
showHelp(false)
|
showHelp(false)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Options(const ArgsList& argList);
|
Options(const std::string& cmdline);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -210,6 +210,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_currentInterpter->m_module->PyEval_RestoreThread(m_currentInterpter->m_state);
|
m_currentInterpter->m_module->PyEval_RestoreThread(m_currentInterpter->m_state);
|
||||||
|
m_currentInterpter->m_module->checkPykd();
|
||||||
|
|
||||||
return m_currentInterpter;
|
return m_currentInterpter;
|
||||||
}
|
}
|
||||||
@ -544,6 +545,8 @@ void PyModule::checkPykd()
|
|||||||
|
|
||||||
} while( false);
|
} while( false);
|
||||||
|
|
||||||
|
PyErr_Clear();
|
||||||
|
|
||||||
if (mainName) Py_DecRef(mainName);
|
if (mainName) Py_DecRef(mainName);
|
||||||
if (mainMod) Py_DecRef(mainMod);
|
if (mainMod) Py_DecRef(mainMod);
|
||||||
if (globals) Py_DecRef(globals);
|
if (globals) Py_DecRef(globals);
|
||||||
|
@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <fstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
#include <regex>
|
||||||
|
|
||||||
#include <DbgEng.h>
|
#include <DbgEng.h>
|
||||||
|
|
||||||
@ -265,6 +267,9 @@ help(
|
|||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
static const std::regex shebangRe("^#!\\s*python([2,3])(?:\\.(\\d))?$");
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
HRESULT
|
HRESULT
|
||||||
CALLBACK
|
CALLBACK
|
||||||
@ -279,7 +284,7 @@ py(
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
Options opts(getArgsList(args));
|
Options opts(args);
|
||||||
|
|
||||||
if (opts.showHelp)
|
if (opts.showHelp)
|
||||||
throw std::exception(printUsageMsg);
|
throw std::exception(printUsageMsg);
|
||||||
@ -287,6 +292,25 @@ py(
|
|||||||
int majorVersion = opts.pyMajorVersion;
|
int majorVersion = opts.pyMajorVersion;
|
||||||
int minorVersion = opts.pyMinorVersion;
|
int minorVersion = opts.pyMinorVersion;
|
||||||
|
|
||||||
|
if ( opts.args.size() > 0 && majorVersion == -1 && minorVersion == -1 )
|
||||||
|
{
|
||||||
|
std::ifstream scriptFile(opts.args[0]);
|
||||||
|
|
||||||
|
std::string firstline;
|
||||||
|
std::getline(scriptFile, firstline);
|
||||||
|
|
||||||
|
std::smatch mres;
|
||||||
|
if (std::regex_match(firstline, mres, shebangRe))
|
||||||
|
{
|
||||||
|
majorVersion = atol(std::string(mres[1].first, mres[1].second).c_str());
|
||||||
|
|
||||||
|
if (mres[2].matched)
|
||||||
|
{
|
||||||
|
minorVersion = atol(std::string(mres[2].first, mres[2].second).c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
getPythonVersion(majorVersion, minorVersion);
|
getPythonVersion(majorVersion, minorVersion);
|
||||||
|
|
||||||
AutoInterpreter autoInterpreter(opts.global, majorVersion, minorVersion);
|
AutoInterpreter autoInterpreter(opts.global, majorVersion, minorVersion);
|
||||||
@ -304,8 +328,6 @@ py(
|
|||||||
PyObjectRef mainMod = PyImport_Import(mainName);
|
PyObjectRef mainMod = PyImport_Import(mainName);
|
||||||
PyObjectRef globals = PyObject_GetAttrString(mainMod, "__dict__");
|
PyObjectRef globals = PyObject_GetAttrString(mainMod, "__dict__");
|
||||||
|
|
||||||
checkPykd();
|
|
||||||
|
|
||||||
InterruptWatch interruptWatch(client);
|
InterruptWatch interruptWatch(client);
|
||||||
|
|
||||||
if (opts.args.empty())
|
if (opts.args.empty())
|
||||||
@ -395,7 +417,7 @@ pip(
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
Options opts(getArgsList(args));
|
Options opts(args);
|
||||||
|
|
||||||
int majorVersion = opts.pyMajorVersion;
|
int majorVersion = opts.pyMajorVersion;
|
||||||
int minorVersion = opts.pyMinorVersion;
|
int minorVersion = opts.pyMinorVersion;
|
||||||
|
Loading…
Reference in New Issue
Block a user