473,473 Members | 1,776 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Windows Debugging w/o MS

Hello all. I have a fairly fundamental question that I have been
googling like crazy, but I can only seem to find really outdated or
unreliable info:

I am trying to build an extension module written in C++ on windows XP.
I am trying to use only open-source tools, such as mingw. I'm using
the Python 2.5 official, and it seems to compile my module just fine
(I'm using the --compiler=mingw32). I can also import the module. The
problem is, when I attempt to use it, I get a segfault. Now, I'm
pretty sure this segfault is just a bug in my C++ code. So of course,
I would like to debug this thing somehow. I tried using the mingw gdb
giving it my python.exe to run, but obviously this python has no debug
info, and wasn't even compiled with mingw. I was hoping it would still
somehow debug my extension module right, but when I do a backtrace
after it segfaults, I get nothing useful.

I've tried compiling python from source, and my extension module,
using MSVC8 (free express version), and I managed to get this to work.
The thing is, I don't want to have to recompile every single python
package I need (wxPython, SciPy, etc).

So basically, I need some general advice for how to compile and debug
extension modules on windows using only open-source tools. I am still
amazed that MSVC7.1 was chosen for the official python release and not
mingw, has anyone explained this?

Thank you so much for your time,
Chris Anderson
May 23 '07 #1
5 1202
I am trying to build an extension module written in C++ on windows XP.
I am trying to use only open-source tools, such as mingw. I'm using
the Python 2.5 official, and it seems to compile my module just fine
(I'm using the --compiler=mingw32). I can also import the module. The
problem is, when I attempt to use it, I get a segfault.
Does it segfault if you import it, or just when you invoke functions
of the module?

You should get it in a state where you can import it just fine, e.g.
by removing stuff from the init function.
Now, I'm
pretty sure this segfault is just a bug in my C++ code. So of course,
I would like to debug this thing somehow. I tried using the mingw gdb
giving it my python.exe to run, but obviously this python has no debug
info, and wasn't even compiled with mingw. I was hoping it would still
somehow debug my extension module right, but when I do a backtrace
after it segfaults, I get nothing useful.
If you can import safely, you should do this:
1. start gdb, with python.exe as the program
2. r(un) it, in gdb
3. import your_module
4. Ctrl-c (or otherwise get back into the debugger)
5. see whether you can set breakpoints on your function

gdb should be able to figure out that your extension module was
loaded and has debug information. Set a breakpoint and see whether
it shows line numbers. If it doesn't, it's because your module does
not have debug information.
I've tried compiling python from source, and my extension module,
using MSVC8 (free express version), and I managed to get this to work.
The thing is, I don't want to have to recompile every single python
package I need (wxPython, SciPy, etc).
You should also be able to compile Python with the mingw compiler,
giving you gdb debug information for all modules.
So basically, I need some general advice for how to compile and debug
extension modules on windows using only open-source tools. I am still
amazed that MSVC7.1 was chosen for the official python release and not
mingw, has anyone explained this?
Python uses the "system compiler" on all systems, and the system
compiler on Microsoft Windows, is, well, Microsoft C.

Using that compiler works better in a number of important use cases.
For example, it is absolutely necessary to be able to compile
extension modules that use C++, COM, and the Microsoft Foundation
Classes. Such extension modules must be compiled with MSC, since
g++ is not capable of compiling them (at least for MFC). One
important extension module that relies on such technology is
Mark Hammond's PythonWin.

If Python was build with mingw, it might be that such modules could
not work anymore, depending on how precisely the mingw build is
done (e.g. what CRT you would use).

Regards,
Martin
May 23 '07 #2
On Tue, 22 May 2007 18:49:04 -0700, "Christopher Anderson"
<si************@gmail.comwrote:
>problem is, when I attempt to use it, I get a segfault. Now, I'm
pretty sure this segfault is just a bug in my C++ code. So of course,
I would like to debug this thing somehow. I tried using the mingw gdb
giving it my python.exe to run, but obviously this python has no debug
info, and wasn't even compiled with mingw. I was hoping it would still
somehow debug my extension module right, but when I do a backtrace
after it segfaults, I get nothing useful.
I have no experience in writing python extension-modules. However, I
would give the following scheme a try. It helped myself a lot while
debugging segfaulting modules plugged into a framework, for which I
haven't had the source-code. It is done easyly and quickly. If it
doesn't work you won't lose a lot of time:

1. At the earliest stage of your own C++-Code, code an infinite loop
depending on a single variable.

e.g.: int i=0; for(;i==0;);

2. When you start your test now and it does not segfault before your
code is reached, the process will be stuck in this loop.

3. Attach gdb to the process using the --pid option. (Unfortunately I
did this only on Unix with dbx. Hope it works on windows and gdb as
well.

4. Look if you are now able to see your source in gdb.

5. Set a breakpoint immediately after the infinite loop.

6. Free the loop by setting the variable i to a value different from
0.

7. You should be able to single step now.

I am not sure if this will work. But it might be worth a try.

Thomas

May 23 '07 #3
>
I've tried compiling python from source, and my extension module,
using MSVC8 (free express version), and I managed to get this to work.
The thing is, I don't want to have to recompile every single python
package I need (wxPython, SciPy, etc).
Debug builds are incompatible with release builds. You'll need to
build every binary extension in debug mode (assuming the original
authors don't provide debug builds).

May 23 '07 #4
Debug builds are incompatible with release builds. You'll need to
build every binary extension in debug mode (assuming the original
authors don't provide debug builds).
Right, and this is what I would like to avoid having to do.

Thanks,
Chris

PS. Sorry for the duplicate olsongt
May 24 '07 #5
On May 24, 5:54 pm, "Christopher Anderson" <sidewinder....@gmail.com>
wrote:
Debug builds are incompatible with release builds. You'll need to
build every binary extension in debug mode (assuming the original
authors don't provide debug builds).

Right, and this is what I would like to avoid having to do.

Thanks,
Chris

PS. Sorry for the duplicate olsongt
Well I guess what I'm saying is, it's a pain to get a python debug
environment up and running, regardless of your toolchain, but there
isn't really any way of avoiding it. (Although I guess this is the
case with any project that uses a bunch of different 3rd party
components.) So you might as well buckle down and do it with whatever
environment you like to use.

I'd say maybe you could figure things out with a map file, but I'm
guessing at least some .dlls are getting their addresses relocated
when they're loaded.

May 24 '07 #6

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

Similar topics

1
by: Günther Rühmann | last post by:
Hi, I´m not sure if i´m right int this group... My problem: I made a vb .net application that reads from AD via System.Directoryservices.Directoryentry. The appliocation enumerates group...
9
by: Günther Rühmann | last post by:
Hi, I´m not sure if i´m right int this group... My problem: I made a vb .net application that reads from AD via System.Directoryservices.Directoryentry. The appliocation enumerates group...
1
by: harinathch | last post by:
Hi, Iam working with myapplication.exe.config file in my vb.net windows application.Its working fine in my development environment. When i test this application in some other machine using exe and...
8
by: J.S. | last post by:
I was under the impression that frames could be used in Windows forms in earlier version of VB. However, in VB 2005 Express I don't see any such tool/control. Is SplitContainer used for this...
1
by: bmaheswar | last post by:
Hi, I have a windows service. it is developed using .Net Framework 1.0. When i try to run that service using CLR PRofile 1.0. Profiler Throws error as show below. See the end of this message...
2
by: Budhi Saputra Prasetya | last post by:
Hi, I managed to create a Windows Form Control and put it on my ASP .NET page. I have done the suggestion that is provided by modifying the security settings. From the stack trace, I would...
0
by: Budhi Saputra Prasetya | last post by:
Hi, I still have the same problem with embedding Windows Control. I'll just requote what I posted last time: I managed to create a Windows Form Control and put it on my ASP .NET page. I...
2
by: sambo251 | last post by:
After running a few updates I get this very annoying "Windows Installer" error #1706 that will ne go away! It keeps saying that it cannot find the file "instantsharedevices.msi", that it is on...
11
by: benoitc | last post by:
I've been having a problem debugging an ASP.NET 1.1 application on an existing Windows XP/Visual Studio 2003 workstation that I've inherited from somebody else. The application builds fine, but...
3
by: shobhitguptait | last post by:
How to Run C#.NET Windows App on N/W with centralized DB using SQL SERVER 2000 Hello All...i m really grate full to c such a website where developers try to help people like us who face problems...
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
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...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.