[Python-bugs-list] [ python-Bugs-456738 ] Support for smoother debugging of C exts

noreply@sourceforge.net noreply@sourceforge.net
Tue, 04 Sep 2001 08:51:54 -0700


Bugs item #456738, was opened at 2001-08-29 19:42
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=456738&group_id=5470

Category: Python Interpreter Core
Group: Feature Request
Status: Open
Resolution: None
Priority: 5
Submitted By: Nobody/Anonymous (nobody)
>Assigned to: Barry Warsaw (bwarsaw)
Summary: Support for smoother debugging of C exts

Initial Comment:
With every new Python release, the first thing that I
do is modify Modules/main.c to add an empty function
called

void Py_DebugTrap(void) { return; }

The purpose of this function is to give me a handy
place to set a breakpoint so that I can debug my C/C++
extension modules. 

It occured to me that this handy trick might be more
generally useful and worthy of inclusion in the
standard distributions.

Thoughts?

-- Michael Aivazis (aivazis@caltech.edu)

----------------------------------------------------------------------

Comment By: Jack Jansen (jackjansen)
Date: 2001-09-04 02:44

Message:
Logged In: YES 
user_id=45365

I think I would like this feature. Actually, I think it
would even be nice to export it to
Python (through sys?). There's something similar in
MacPython (the MacOS
DebugStr() routine) and I use it a lot.

The advantage of a separate routine (as opposed to setting a
breakpoint) is that
you can put complex conditions in your code for when you
want to call the routine.
This could conceivably be done with conditional breakpoints
too, but it tends to be
much more of a hassle. Especially going from Python code to
the C debugger at a
specific point is pretty difficult.

----------------------------------------------------------------------

Comment By: Martin v. Löwis (loewis)
Date: 2001-09-03 14:36

Message:
Logged In: YES 
user_id=21627

I don't think this is universally useful. It seems that, 
at a minimum, you have to add calls to Py_DebugTrap into 
the module to make it useful, right? Then why can't you 
just set breakpoints on the lines that you want to call 
Py_DebugTrap?

If the problem is that you cannot set a breakpoint on code 
that is not yet loaded, I can give you a number of 
alternatives:
- any advanced debugger should offer to break when a 
shared library is loaded. gdb does.
- you can set a breakpoint on Py_InitModule4 (or whatever 
your extension module calls)
- you can set a breakpoint on dlsym (or whatever your 
shared library system uses to find the address of the init 
function)
- you can statically link your extension module into the 
Python interpreter, and avoid DLL problems altogether.

If these suggestions don't address your problem, please 
explain in more detail what your problem is. Otherwise, I 
propose to close this report as "won't fix".


----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=456738&group_id=5470