Debugging embedded python

fotis fotis77k at fmail.co.uk
Mon Jul 4 04:20:54 EDT 2005


hello there!
I am playing with embedded python these days. I wrote sth like this:

------------------------------ Code -------------------------------
#include <Python.h>
#include <iostream>
#include <cmath>

/* Return the square root of an argument */
static PyObject* Fotis_root(PyObject *self, PyObject *args)
{
	double d=0;
    if(!PyArg_ParseTuple(args,"d",&d))
        return NULL;
    return Py_BuildValue("d", sqrt(d));
}

static PyMethodDef FotisMethods[] = {
    {"root",Fotis_root, METH_VARARGS,
     "Return the root of a double."},
    {NULL, NULL, 0, NULL}
};

int main(int argc,char** argv)
{
	Py_Initialize();
	Py_InitModule("fotis", FotisMethods);
	PyRun_SimpleString("from fotis import root");
	PyRun_SimpleString("print \"Testing embedded python...\"");
	FILE* fp=stdin;
	char *filename="Embedded";
	PyRun_InteractiveLoop(fp,filename);
	Py_Finalize();
 return 0;
}

------------------------------------------------------------------
I linked it to python24.lib (under eclipse cdt/win2k) and it compiles,
links and runs fine.
The problem is when I try to debug it (gdb). I cannot go single
stepping into the code, more than one threads seem to be running, I get
messages like "No source file named d:/workspace/pyTest/main.cpp", and
if I set a breakpoint to the function Fotis_root then I cannot see any
variables. In fact I cannot see no stack, no registers nothing, within
this function!
With msvc 6.0 debuging goes smoothly.
Any ideas?
Thank you.
Fotis._




More information about the Python-list mailing list