By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,500 Members | 1,571 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,500 IT Pros & Developers. It's quick & easy.

Debugging embedded python

P: n/a
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._

Jul 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hello Fotis,
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!

I *think* that you need to tell GDB where are the source directories (try
"help dir")

HTH.
--
------------------------------------------------------------------------
Miki Tebeka <mi*********@zoran.com>
http://tebeka.bizhat.com
The only difference between children and adults is the price of the toys

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (Cygwin)

iD8DBQFCyTUp8jAdENsUuJsRAuOgAKCntTlkEUwThAfNZou+hp cjldaiUACfd8qv
UVRflvoUJ9Xxra3JW+DfJWg=
=Nd14
-----END PGP SIGNATURE-----

Jul 21 '05 #2

P: n/a
Thank's a lot miki for your response!

It seems that this problem is now solved, yet a new one now occured.
And the name of my new problem is...

"<Stack is not available: Cannot access memory at address 0x1.>"

Let me rewrite the code a little bit more clearly...

//************************************************** *****************
// C O D E
//************************************************** *****************
01
//__________________________________________________ _________________
02 // Includes mpla, mpla mpla...
03 #include <Python.h>
04 #include <iostream>
05 #include <cmath>
06 using namespace std;
07
08
//__________________________________________________ _________________
09 // My function
10 /* Return the sqrt of a double */
11 static PyObject* Fotis_root(PyObject *self, PyObject *args)
12 {
13 double d=0;
14 if(!PyArg_ParseTuple(args,"d",&d)) return NULL;
15 return Py_BuildValue("d", sqrt(d));
16 }
17
18
//__________________________________________________ _________________
19 // Some python module stuff
20 static PyMethodDef FotisMethods[] = {
21 {"root",Fotis_root, METH_VARARGS,
22 "Return the root of a double."},
23 {NULL, NULL, 0, NULL}
23 };
24
25
//__________________________________________________ _________________
26 // Main program
27 int main(int argc,char** argv)
28 {
29 Py_Initialize();
30 Py_InitModule("fotis", FotisMethods);
31 PyRun_SimpleString("from fotis import root");
32 FILE* fp=stdin;
33 char *filename="Solver";
34 PyRun_InteractiveLoop(fp,filename); 35 Py_Finalize();
36 return 0;
37 }

Now lets say i set two breakpoints: line 29, and line 13. This is what
happens:
1. Breakpoint at line 29: There is a strange combination of next, step,
and other stuff that can move me from line 29 to line 34. No matter how
deeply I digged everywhere I cannot realy understand what really
happens there, but what the hack this is not what I'm really interested
in. by the way if i try too many steps then there is no way back...
2. Breakpoint at line 13: When I finally reach the much awaited line
34, the python interpreter is there and running and waiting for my
commands, which here is the fotis.root(double) command. when I give
though this command control is totally lost: i get the message
described above and after that everything seems to be dead. I really do
not know where I am, why am I there, and what exactly I am doing at the
point that I am.

What is really happening?

Any help will be very appreciated.
fotis._

Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.