关于pyd文件的调试

135 views
Skip to first unread message

Junze Liu

unread,
Jan 26, 2013, 2:17:36 AM1/26/13
to python-...@googlegroups.com
 最近,我使用python和C++建立了一个混合系统,我使用boostpython封装了一个pythonDll class,(我不能保证这个class的健壮性),这样我得到了一个test.pyd的文件,我在abc.py文件中使用到了这个封装的模块,里面含有import pthonDll这样的语句。之后我在我的C++主工程之中嵌入了python解释器,解释器来执行我的abc.py文件,到这里一切良好。但是我知道我的class有问题,每当执行到执行py文件的时候,程序就会崩溃,我需要进行调试我封装pythonDll的时候所用到的源码,如何进行调试???
    C++生成pyd文件,py使用pyd文件,C++嵌入解释器解释py文件,这个流程,反向debug pyd文件能行么?不能行,怎么解决呢? 
生成pyd的代码
execute.h
C/C++ code
?
1
2
3
4
5
6
7
8
9
10
#include <string> 
 
class Excute 
public
        Excute(){} 
        int getIoReuslt(std::string ioStr); 
        int getSignal(); 
}; 
#endif 

execute.cpp
C/C++ code
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
int Excute::getIoReuslt(std::string ioStr) 
        //do something here
        return 1; 
 
int Excute::getSignal() 
        int i = rand()%2; 
        return i; 
 
BOOST_PYTHON_MODULE(pythonDll) 
        using namespace boost::python; 
        class_<Excute>("Excute", init<>()) 
                .def("getIoResult", &Excute::getIoReuslt) 
                .def("getSignal", &Excute::getSignal) 
                


test.py里面的内容是:
Python code
?
1
2
3
4
5
from pythonDll import*
h=Excute()
h.excute("abc")
print h.getSignal()
...


嵌入python解释器的代码:
C/C++ code
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int main(int argc, char* argv[]) 
        Py_Initialize(); 
        FILE * fp = fopen("$PATH/test.py""r"); 
        if (fp == NULL) 
        
            return 1; 
        
        PyRun_SimpleString("execfile($PATH/test.py')"); 
        Py_Finalize(); 
 
        system("Pause"); 
 
        return 0; 
怎么调试pyd,只有我的主程序启动之后,才能点击按钮,启动解释器,解释器执行脚本.py,脚本中有C++模块,而C++模块中源码怎么跳进去?
Reply all
Reply to author
Forward
0 new messages