/* ****************************************************************************
*
* Copyright (c) Microsoft Corporation.
*
* This source code is subject to terms and conditions of the Apache License, Version 2.0. A
* copy of the license can be found in the License.html file at the root of this distribution. If
* you cannot locate the Apache License, Version 2.0, please send an email to
* vspython@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
* by the terms of the Apache License, Version 2.0.
*
* You must not remove this notice, or any other, from this software.
*
* Contributor: Fabio Zadrozny
*
* Based on PyDebugAttach.cpp from PVTS. Windows only.
* Initially we did an attach completely based on shellcode which got the
* GIL called PyRun_SimpleString with the needed code and was done with it
* (so, none of this code was needed).
* Now, newer version of Python don't initialize threading by default, so,
* most of this code is done only to overcome this limitation (and as a plus,
* if there's no code running, we also pause the threads to make our code run).
*
* On Linux the approach is still the simpler one (using gdb), so, on newer
* versions of Python it may not work unless the user has some code running
* and threads are initialized.
* I.e.:
*
* The user may have to add the code below in the start of its script for
* a successful attach (if he doesn't already use threads).
*
* from threading import Thread
* Thread(target=str).start()
*
* -- this is the workaround for the fact that we can't get the gil
* if there aren't any threads (PyGILState_Ensure gives an error).
* ***************************************************************************/
// Access to std::cout and std::endl
#include <iostream>
// DECLDIR will perform an export for us
#define DLL_EXPORT
#include "attach.h"
#include "stdafx.h"
#include "python.h"
#pragma comment(lib, "kernel32.lib")
#pragma comment(lib, "user32.lib")
#pragma comment(lib, "advapi32.lib")
#pragma comment(lib, "psapi.lib")
// _Always_ is not defined for all versions, so make it a no-op if missing.
#ifndef _Always_
#define _Always_(x) x
#endif
using namespace std;
typedef int (Py_IsInitialized)();
typedef void (PyEval_Lock)(); // Acquire/Release lock
typedef void (PyThreadState_API)(PyThreadState *); // Acquire/Release lock
typedef PyInterpreterState* (PyInterpreterState_Head)();
typedef PyThreadState* (PyInterpreterState_ThreadHead)(PyInterpreterState* interp);
typedef PyThreadState* (PyThreadState_Next)(PyThreadState *tstate);
typedef PyThreadState* (PyThreadState_Swap)(PyThreadState *tstate);
typedef int (PyRun_SimpleString)(const char *command);
typedef PyObject* (PyDict_New)();
typedef PyObject* (PyModule_New)(const char *name);
typedef PyObject* (PyModule_GetDict)(PyObject *module);
typedef PyObject* (Py_CompileString)(const char *str, const char *filename, int start);
typedef PyObject* (PyEval_EvalCode)(PyObject *co, PyObject *globals, PyObject *locals);
typedef PyObject* (PyDict_GetItemString)(PyObject *p, const char *key);
typedef PyObject* (PyObject_CallFunctionObjArgs)(PyObject *callable, ...); // call w/ varargs, last arg should be NULL
typedef void (PyErr_Fetch)(PyObject **, PyObject **, PyObject **);
typedef PyObject* (PyEval_GetBuiltins)();
typedef int (PyDict_SetItemString)(PyObject *dp, const char *key, PyObject *item);
typedef int (PyEval_ThreadsInitialized)();
typedef void (Py_AddPendingCall)(int (*func)(void *), void*);
typedef PyObject* (PyInt_FromLong)(long);
typedef PyObject* (PyString_FromString)(const char* s);
typedef void PyEval_SetTrace(Py_tracefunc func, PyObject *obj);
typedef void (PyErr_Restore)(PyObject *type, PyObject *value, PyObject *traceback);
typedef void (PyErr_Fetch)(PyObject **ptype, PyObject **pvalue, PyObject **ptraceback);
typedef PyObject* (PyErr_Occurred)();
typedef PyObject* (PyErr_Print)();
typedef PyObject* (PyImport_ImportModule) (const char *name);
typedef PyObject* (PyObject_GetAttrString)(PyObject *o, const char *attr_name);
typedef PyObject* (PyObject_HasAttrString)(PyObject *o, const char *attr_name);
typedef PyObject* (PyObject_SetAttrString)(PyObject *o, const char *attr_name, PyObject* value);
typedef PyObject* (PyBool_FromLong)(long v);
typedef enum { PyGILState_LOCKED, PyGILState_UNLOCKED } PyGILState_STATE;
typedef PyGILState_STATE(PyGILState_Ensure)();
typedef void (PyGILState_Release)(PyGILState_STATE);
typedef unsigned long (_PyEval_GetSwitchInterval)(void);
typedef void (_PyEval_SetSwitchInterval)(unsigned long microseconds);
typedef void* (PyThread_get_key_value)(int);
typedef int (PyThread_set_key_value)(int, void*);
typedef void (PyThread_delete_key_value)(int);
typedef PyGILState_STATE PyGILState_EnsureFunc(void);
typedef void PyGILState_ReleaseFunc(PyGILState_STATE);
typedef PyObject* PyInt_FromSize_t(size_t ival);
typedef PyThreadState *PyThreadState_NewFunc(PyInterpreterState *interp);
class PyObjectHolder;
PyObject* GetPyObjectPointerNoDebugInfo(bool isDebug, PyObject* object);
void DecRef(PyObject* object, bool isDebug);
void IncRef(PyObject* object, bool isDebug);
#define MAX_INTERPRETERS 10
// Helper class so we can use RAII for freeing python objects when they go out of scope
class PyObjectHolder {
private:
PyObject* _object;
public:
bool _isDebug;
PyObjectHolder(bool isDebug) {
_object = nullptr;
_isDebug = isDebug;
}
PyObjectHolder(bool isDebug, PyObject *object) {
_object = object;
_isDebug = isDebug;
};
PyObjectHolder(bool isDebug, PyObject *object, bool addRef) {
_object = object;
_isDebug = isDebug;
if (_object != nullptr && addRef) {
GetPyObjectPointerNoDebugInfo(_isDebug, _object)->ob_refcnt++;
}
};
PyObject* ToPython() {
return _object;
}
~PyObjectHolder() {
DecRef(_object, _isDebug);
}
PyObject* operator* () {
return GetPyObjectPointerNoDebugInfo(_isDebug, _object);
}
};
class InterpreterInfo {
public:
InterpreterInfo(HMODULE module, bool debug) :
Interpreter(module),
CurrentThread(nullptr),
NewThreadFunction(nullptr),
PyGILState_Ensure(nullptr),
Version(PythonVersion_Unknown),
Call(nullptr),
IsDebug(debug),
SetTrace(nullptr),
PyThreadState_New(nullptr),
ThreadState_Swap(nullptr) {
}
~InterpreterInfo() {
if (NewThreadFunction != nullptr) {
delete NewThreadFunction;
}
}
PyObjectHolder* NewThreadFunction;
PyThreadState** CurrentThread;
HMODULE Interpreter;
PyGILState_EnsureFunc* PyGILState_Ensure;
PyEval_SetTrace* SetTrace;
PyThreadState_NewFunc* PyThreadState_New;
PyThreadState_Swap* ThreadState_Swap;
PythonVersion GetVersion() {
if (Version == PythonVersion_Unknown) {
Version = ::GetPythonVersion(Interpreter);
}
return Version;
}
PyObject_CallFunctionObjArgs* GetCall() {
if (Call == nullptr) {
Call = (PyObject_CallFunctionObjArgs*)GetProcAddress(Interpreter, "PyObject_CallFunctionObjArgs");
}
return Call;
}
bool EnsureSetTrace() {
if (SetTrace == nullptr) {
auto setTrace = (PyEval_SetTrace*)(void*)GetProcAddress(Interpreter, "PyEval_SetTrace");
SetTrace = setTrace;
}
return SetTrace != nullptr;
}
bool EnsureThreadStateSwap() {
if (ThreadState_Swap == nullptr) {
auto swap = (PyThreadState_Swap*)(void*)GetProcAddress(Interpreter, "PyThreadState_Swap");
ThreadState_Swap = swap;
}
return ThreadState_Swap != nullptr;
}
bool EnsureCurrentThread() {
if (CurrentThread == nullptr) {
auto curPythonThread = (PyThreadState**)(void*)GetProcAddress(
Interpreter, "_PyThreadState_Current");
CurrentThread = curPythonThread;
没有合适的资源?快使用搜索试试~ 我知道了~
pydev 最新版 eclipse插件
共1447个文件
py:872个
gif:192个
png:109个
4星 · 超过85%的资源 需积分: 10 23 下载量 172 浏览量
2015-05-03
08:08:05
上传
评论
收藏 15.67MB ZIP 举报
温馨提示
pydev 最新版 eclipse插件 PyDev is open source and depends on your contributions! This may be in the form of bug fixes, answers on stackoverflow, new features... Another option is financially supporting it
资源推荐
资源详情
资源评论
收起资源包目录
pydev 最新版 eclipse插件 (1447个子文件)
compile_dll.bat 398B
attach_linux.c 10KB
PyFocusExplorerAction.class 1KB
Activator.class 894B
command_template 719B
attach.cpp 59KB
stdafx.cpp 999B
_ctypes.dll 281KB
attach_amd64.dll 280KB
attach_x86.dll 226KB
PYDEV.DSA 1KB
PYDEV.DSA 1KB
PYDEV.DSA 1KB
PYDEV.DSA 1KB
PYDEV.DSA 1KB
PYDEV.DSA 1KB
PYDEV.DSA 1KB
PYDEV.DSA 1KB
PYDEV.DSA 1KB
PYDEV.DSA 1KB
PYDEV.DSA 1KB
PYDEV.DSA 1KB
PYDEV.DSA 1KB
PYDEV.DSA 1KB
PYDEV.DSA 1KB
PYDEV.DSA 1KB
PYDEV.DSA 1KB
PYDEV.DSA 1KB
PYDEV.DSA 1KB
PYDEV.DSA 1KB
PYDEV.DSA 1KB
PYDEV.DSA 1KB
attach_x86_64.dylib 18KB
attach_x86.dylib 18KB
wsgiref.egg-info 187B
wininst-9.0-amd64.exe 219KB
wininst-9.0.exe 192KB
wininst-7.1.exe 64KB
wininst-8.0.exe 60KB
wininst-6.0.exe 60KB
pydev_ctrl_1.exsd 5KB
pydev_builder.exsd 4KB
pydev_python_module_resolver.exsd 4KB
pydev_pythonpath_contrib.exsd 4KB
pydev_parser_observer.exsd 4KB
pydev_debug_command_line_participant.exsd 3KB
pydev_hover.exsd 3KB
pydev_completion.exsd 3KB
pydev_debug_console_input_listener.exsd 3KB
pydev_debug_preferences_page.exsd 3KB
pydev_preferences_provider.exsd 3KB
pydev_modules_observer.exsd 3KB
pydev_organize_imports.exsd 3KB
pydev_pyedit_listener.exsd 3KB
pydev_globals_browser.exsd 3KB
pydev_simpleassist.exsd 3KB
pydev_quick_outline.exsd 3KB
pydev_refactoring.exsd 3KB
pydev_formatter.exsd 3KB
pydev_manager_observer.exsd 3KB
pydev_view_created_observer.exsd 3KB
pydev_interpreter_observer.exsd 3KB
pydev_interpreter_provider.exsd 2KB
pydev_interpreter_new_custom_entries.exsd 2KB
pydev_interpreter_info_builder.exsd 2KB
banner-prefs.gif 3KB
appengine-noborder-120x30.gif 1KB
class_obj.gif 1KB
class_obj.gif 1KB
mylar.gif 1KB
__imp_obj.gif 1KB
__imp_obj.gif 1KB
method_obj.gif 1000B
method_obj.gif 1000B
remove_all.gif 992B
jar_remove_l_obj.gif 991B
search_docs.gif 987B
search_docs.gif 987B
sample.gif 983B
sample.gif 983B
packagefolder_obj_remove.gif 979B
app_engine.gif 973B
app_engine_16_16.gif 968B
start_debug_server.gif 947B
search.gif 942B
terminate_all.gif 942B
search.gif 942B
terminate_all.gif 942B
python.gif 932B
method_obj.gif 926B
class_obj.gif 902B
term_debug_server.gif 895B
attrpub_obj.gif 884B
attrpub_obj.gif 884B
attr_obj_imp.gif 871B
imp_rel_obj.gif 862B
imp_rel_obj.gif 862B
imp_obj.gif 859B
imp_obj.gif 859B
imp_rel_obj.gif 857B
共 1447 条
- 1
- 2
- 3
- 4
- 5
- 6
- 15
资源评论
- 慕兰骆驼2015-09-20插件倒是没问题,可是在我的eclipse环境下不好用。应该是个人问题,试了好几个也不行。
zhaohui534
- 粉丝: 2
- 资源: 59
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功