looking for python object debugging hints

ramb at synopsys.com ramb at synopsys.com
Mon Jul 31 11:33:25 EDT 2000


I've written some code to implement a new python object and I'm having
some trouble with it. My code to implement the new object is written
both in C and in Python. 

Here is the situation:

A python script imports my module and then starts calling
various functions in my C shared library. The problem is
that if I use gdb on the python binary my shared library
is not loaded until the script starts running and that
is too late to set a break point. What I want is some way
to make it easy to use a debugger to debug my dynamically
loaded shared library.

Here are some of the ideas I have:

  1. Build a statically linked Python executable and completely
     avoid the whole problem.

  2. Modify my shared library so that once it is loaded into the 
     python process the shared library will cause the python process
     to stop until the debugger attachs to the python process.

  3. Invoke the debugger (as a separate process) from the shared library
     that is loaded into the python process.

  4. Use sleep or some other method to slow down the execution of the
     shared library.

I know how to do 1 and I'm pretty sure I could do 3 via some combination
of system() calls. What I really want is option 2. But I'm not sure how
to do that. Option 4 would also be easy, but it strikes me as ugly, and I'd
rather use a solution that has atleast some amount of elegance to it.

Does anyone know how (under unix) to make a process stop and wait until
a debugger attaches to the process?

Alternatively if you have another way to solve this problem it would
be great to hear about it.

Thanks for any ideas.
-Ram



More information about the Python-list mailing list