473,403 Members | 2,183 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

[Howto] Compiling debug Python extensions for non-debug Python

Every few months I get to working on a Python C extension (built with
distutils) and discover a pointer error or the like where I'd like to be
able to step into my DLL and see where the extension is going wonky.

Now, the "proper" way to debug a DLL is apparently to build Python in
debug mode (i.e. with the _d form dll), then build each and every
extension I depend on (in debug mode), and then build each of my own
extensions in debug mode. That takes forever when there's 8 or 9
complex-to-build extensions involved in the system generating the error,
and is pointless when I could just print-debug in 1/100th of the time to
fix the particular error.

Now, it so happens that there's no reason I know of to do all that
rebuilding when all you want to do is to generate a program database and
see what's going on *in your own extension*. You can quite readily
create a debuggable DLL linked against the non-debug Python and all its
extensions with a 2 or 3 line change to msvccompiler.py in distutils. I
discovered that quite a while ago, but as the change is to a core Python
file, I tend to forget about it and overwrite it when I upgrade Python
and then spend a few hours re-discovering the exact switches, so, for my
own memory, and for any other extension writers who want this kind of
down-and-dirty debugging, here's the changes required:

In lib/distutils/msvccompiler.py:

self.compile_options = [
'/nologo',
'/Od', # turn off optimisations (allow debug)
'/MD', '/W3', '/GX',
'/Zi', # create a pdb file for the object files we create,
/Z7 works fine too
]
self.ldflags_shared = [
'/DLL', '/nologo', '/INCREMENTAL:YES',
'/DEBUG', # do debug-mode linking
]

then rebuild, forcing a recompile to make sure everything's been built
with the new flags.

There's probably some perfectly good reason not to do this as the
default for distutils "debug" mode for building a PYD, but I find it
*very* helpful, and hopefully others will as well.

Keywords: Visual C MSVC++ VC++ Win32 debug extension dll pyd distutils

Enjoy all,
Mike

_______________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://members.rogers.com/mcfletch/


Jul 18 '05 #1
3 3348
Mike C. Fletcher wrote:
Every few months I get to working on a Python C extension (built with
distutils) and discover a pointer error or the like where I'd like to be
able to step into my DLL and see where the extension is going wonky.

....

I have had the same problem in Linux. In the old DOS Borland Debugger, I
could tell the debugger to display a particular source code file. Then I
could set a breakpoint in it. Is this possible in gdb or some other UNIX
debugger? Has anyone ported the Borland Debugger to Linux?

Jul 18 '05 #2
Edward C. Jones:
I have had the same problem in Linux. In the old DOS Borland Debugger, I
could tell the debugger to display a particular source code file. Then I
could set a breakpoint in it. Is this possible in gdb or some other UNIX
debugger? Has anyone ported the Borland Debugger to Linux?


Many of them do although it can be less than obvious how to do it.
KDevelop can do this although IIRC you first need to set up a dummy project
before being able to run an arbitrary executable. I have had problems with
Linux debuggers using inaccurate line number information although some of
this had been caused by using files from Windows with their \r\n line
endings. My current favourite Linux debugger is KDbg as it isn't an IDE and
so doesn't try to make you create project files.

Neil
Jul 18 '05 #3
Edward C. Jones wrote:
I have had the same problem in Linux. In the old DOS Borland Debugger, I
could tell the debugger to display a particular source code file. Then I
could set a breakpoint in it. Is this possible in gdb or some other UNIX
debugger? Has anyone ported the Borland Debugger to Linux?


In gdb, type

b <source>:<line>

Regards,
Martin

Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Sebastian Morawietz | last post by:
Hi, I'm busy porting a PHP-Extension written by the company I work for from Linux to Win32 (XP). Everything worked fine. I fixed the errors and warnings, copied the dll to the extensions...
0
by: tyousaf | last post by:
Hi i am new to mysql and mysql++, i have installed mysql server, it is running fine. i also installed "mysql++-1.7.9gcc3.2-2.i386.rpm" (i have gcc 3.3) , first of all as the readme file says to do...
8
by: Vladimir | last post by:
Hello, I have a table in MS Access database. It has one field (with BYTE datatype) that has several properties set in Lookup tab of table Design View. Display Control = Combo Box. Row Source...
3
by: Dan Sikorsky | last post by:
How can I install the Portal starter kit to a different Solution/Project name, having a different SQL Server database name? I'd like to start a new solution using the Portal starter kit as a...
59
by: Anando | last post by:
Hi, I have a linear singly linked list of 100 elements. I would like to prune it such that only user specified elements (say only the elements 1, 13, 78 and 100 of the original list) survive...
1
by: smack | last post by:
Does anyone know how to create an extension DLL for Windows. I have no problem compiling my selfdevelopt extension for Linux, but can't seem to find any relevant information on how to compile an...
13
by: Albert | last post by:
Hi I'm using the lcc compiler for win32. I tried compiling a program but there's an error stating: "cpp: Can't open input file clrscr()" I don't get it - I've included <tcconio.h>. (strange why...
15
by: Frank | last post by:
Before I start, please let's not discuss whether goto is evil or not. For generated code, this can make perfect sense. It would be interesting to know a trick how to get C to do a goto to an...
7
by: Peted | last post by:
Hi, im hoping someone cane provide or point to a definitive accurate explantion of dotnet compilation when run and the best way to optimise peformace when dotnet code is run first time and...
13
by: Adem | last post by:
HOWTO: const and pointer variants in C and C++ : void test() { int n = 1; // n is non-const data of type int ++n; // ok const int c = 2; //...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.