mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-20 03:23:23 +08:00
[pykd_ext_2.0] updated : pykd help command
git-svn-id: https://pykd.svn.codeplex.com/svn@90991 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
parent
ceba5b7857
commit
27db13b5de
@ -82,6 +82,7 @@ PyObject* PyProperty_Type();
|
||||
void PyErr_Fetch(PyObject **ptype, PyObject **pvalue, PyObject **ptraceback);
|
||||
void PyErr_NormalizeException(PyObject**exc, PyObject**val, PyObject**tb);
|
||||
void PyErr_SetString(PyObject *type, const char *message);
|
||||
void PyErr_Clear();
|
||||
|
||||
PyObject* PyFile_FromString(char *filename, char *mode);
|
||||
FILE* PyFile_AsFile(PyObject *pyfile);
|
||||
|
@ -98,7 +98,8 @@ public:
|
||||
char* (__stdcall *PyString_AsString)(PyObject *string);
|
||||
void(__stdcall *PyErr_Fetch)(PyObject **ptype, PyObject **pvalue, PyObject **ptraceback);
|
||||
void(__stdcall *PyErr_NormalizeException)(PyObject**exc, PyObject**val, PyObject**tb);
|
||||
void (__stdcall *PyErr_SetString)(PyObject *type, const char *message);
|
||||
void(__stdcall *PyErr_SetString)(PyObject *type, const char *message);
|
||||
void(__stdcall *PyErr_Clear)();
|
||||
PyObject* (__stdcall *PyImport_AddModule)(const char *name);
|
||||
PyObject* (__stdcall *PyClass_New)(PyObject* className, PyObject* classBases, PyObject* classDict);
|
||||
PyObject* (__stdcall *PyInstance_New)(PyObject *classobj, PyObject *arg, PyObject *kw);
|
||||
@ -392,6 +393,7 @@ PyModule::PyModule(int majorVesion, int minorVersion)
|
||||
*reinterpret_cast<FARPROC*>(&PyErr_Fetch) = GetProcAddress(m_handlePython, "PyErr_Fetch");
|
||||
*reinterpret_cast<FARPROC*>(&PyErr_NormalizeException) = GetProcAddress(m_handlePython, "PyErr_NormalizeException");
|
||||
*reinterpret_cast<FARPROC*>(&PyErr_SetString) = GetProcAddress(m_handlePython, "PyErr_SetString");
|
||||
*reinterpret_cast<FARPROC*>(&PyErr_Clear) = GetProcAddress(m_handlePython, "PyErr_Clear");
|
||||
*reinterpret_cast<FARPROC*>(&PyImport_AddModule) = GetProcAddress(m_handlePython, "PyImport_AddModule");
|
||||
*reinterpret_cast<FARPROC*>(&PyImport_ImportModule) = GetProcAddress(m_handlePython, "PyImport_ImportModule");
|
||||
*reinterpret_cast<FARPROC*>(&PyClass_New) = GetProcAddress(m_handlePython, "PyClass_New");
|
||||
@ -470,20 +472,23 @@ void PyModule::deactivate()
|
||||
|
||||
void PyModule::checkPykd()
|
||||
{
|
||||
if (m_pykdInit)
|
||||
return;
|
||||
|
||||
PyObject* pykdMod = PyImport_ImportModule("pykd");
|
||||
|
||||
if (!pykdMod)
|
||||
throw std::exception("Pykd package is not installed.You can install it by command \"!pip install pykd\"");
|
||||
|
||||
{
|
||||
PyObject* mainName = isPy3 ? PyUnicode_FromString("__main__") : PyString_FromString("__main__");
|
||||
PyObject* mainMod = PyImport_Import(mainName);
|
||||
PyObject* globals = PyObject_GetAttrString(mainMod, "__dict__");
|
||||
PyObject* result = PyRun_String("__import__('pykd').initialize()\n", Py_file_input, globals, globals);
|
||||
|
||||
if (mainName) Py_DecRef(mainName);
|
||||
if (mainMod) Py_DecRef(mainMod);
|
||||
if (globals) Py_DecRef(globals);
|
||||
if (result) Py_DecRef(result);
|
||||
}
|
||||
|
||||
if (pykdMod) Py_DecRef(pykdMod);
|
||||
|
||||
m_pykdInit = true;
|
||||
@ -697,6 +702,11 @@ void PyErr_NormalizeException(PyObject**exc, PyObject**val, PyObject**tb)
|
||||
PythonSingleton::get()->currentInterpreter()->m_module->PyErr_NormalizeException(exc, val, tb);
|
||||
}
|
||||
|
||||
void PyErr_Clear()
|
||||
{
|
||||
PythonSingleton::get()->currentInterpreter()->m_module->PyErr_Clear();
|
||||
}
|
||||
|
||||
void PyErr_SetString(PyObject *type, const char *message)
|
||||
{
|
||||
PythonSingleton::get()->currentInterpreter()->m_module->PyErr_SetString(type, message);
|
||||
|
@ -209,7 +209,6 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="export.def" />
|
||||
<None Include="packages.pykd_bootstrapper_vc120.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="version.rc" />
|
||||
|
@ -70,9 +70,6 @@
|
||||
<None Include="export.def">
|
||||
<Filter>Source Files</Filter>
|
||||
</None>
|
||||
<None Include="packages.pykd_bootstrapper_vc120.config">
|
||||
<Filter>Source Files</Filter>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="version.rc">
|
||||
|
@ -169,13 +169,49 @@ info(
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static const char printUsageMsg[] =
|
||||
"\n"
|
||||
"usage:\n"
|
||||
"!py [options] [file]\n"
|
||||
"\n"
|
||||
"!help\n"
|
||||
"\tprint this text\n"
|
||||
"\n"
|
||||
"!info\n"
|
||||
"\tlist installed python interpreters\n"
|
||||
"\n"
|
||||
"!py [version] [options] [file]\n"
|
||||
"\trun python script or REPL\n"
|
||||
"\n"
|
||||
"\tVersion:\n"
|
||||
"\t-2 : use Python2\n"
|
||||
"\t-2.x : use Python2.x\n"
|
||||
"\t-3 : use Python3\n"
|
||||
"\t-3.x : use Python3.x\n"
|
||||
"\n"
|
||||
"\tOptions:\n"
|
||||
"\t-g --global : run code in the common namespace\n"
|
||||
"\t-l --local : run code in the isolate namespace\n"
|
||||
"!pip\n"
|
||||
"!info\n";
|
||||
"\t-l --local : run code in the isolated namespace\n"
|
||||
"\n"
|
||||
"\tcommand samples:\n"
|
||||
"\t\"!py\" : run REPL\n"
|
||||
"\t\"!py --local\" : run REPL in the isolated namespace\n"
|
||||
"\t\"!py -g script.py 10 \"string\"\" : run script file with argument in the commom namespace\n"
|
||||
"\n"
|
||||
"!pip [version] [args]\n"
|
||||
"\trun pip package manager\n"
|
||||
"\n"
|
||||
"\tVersion:\n"
|
||||
"\t-2 : use Python2\n"
|
||||
"\t-2.x : use Python2.x\n"
|
||||
"\t-3 : use Python3\n"
|
||||
"\t-3.x : use Python3.x\n"
|
||||
"\n"
|
||||
"\tpip command samples:\n"
|
||||
"\t\"pip list\" : show all installed packagies\n"
|
||||
"\t\"pip install pykd\" : install pykd\n"
|
||||
"\t\"pip install --upgrade pykd\" : upgrade pykd to the latest version\n"
|
||||
"\t\"pip show pykd\" : show info about pykd package\n"
|
||||
;
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -200,13 +236,6 @@ help(
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static const char consoleScript[] =
|
||||
"import pykd\n"
|
||||
"from pykd import *\n"
|
||||
"import code\n"
|
||||
"code.InteractiveConsole(globals()).interact()\n";
|
||||
|
||||
|
||||
extern "C"
|
||||
HRESULT
|
||||
CALLBACK
|
||||
@ -252,7 +281,9 @@ py(
|
||||
|
||||
if (opts.args.empty())
|
||||
{
|
||||
PyObjectRef result = PyRun_String(consoleScript, Py_file_input, globals, globals);
|
||||
PyObjectRef result = PyRun_String("import pykd\nfrom pykd import *\n", Py_file_input, globals, globals);
|
||||
PyErr_Clear();
|
||||
result = PyRun_String("import code\ncode.InteractiveConsole(globals()).interact()\n", Py_file_input, globals, globals);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -342,7 +373,7 @@ pip(
|
||||
|
||||
getPythonVersion(majorVersion, minorVersion);
|
||||
|
||||
AutoInterpreter autoInterpreter(opts.global, majorVersion, minorVersion);
|
||||
AutoInterpreter autoInterpreter(true, majorVersion, minorVersion);
|
||||
|
||||
PyObjectRef dbgOut = make_pyobject<DbgOut>(client);
|
||||
PySys_SetObject("stdout", dbgOut);
|
||||
|
Loading…
Reference in New Issue
Block a user