views:

803

answers:

5

Leading on from the answer to another question about bugs in the Delphi IDE, does anyone know if there is a way to improve the multi-threaded debugging functionality of the IDE, or if not, at least why it is so bad on occasion?

When you have multiple threads within a program, stepping through the code with F7 or F8 can often lead to either very long pauses, or the whole IDE just locks ups. This is especially apparent when you leave or enter a method or procedure. The debugger always seems to be fine for single threaded applications.

PS. The version I'm using is 2007

A: 

Yes, debugging a multithreaded application is a hassle. Because you are constantly swapping from one thread to another.

Gamecat
+3  A: 

From my experience multi threaded debugging is much nicer using Vista and Delphi 2009 than XP with Delphi 2007.

First, the ide is significantly more stable.

Second, in Delphi 2009 on vista the debugger can show you where deadlocks are occurring.

If you have to use Delphi 2007, I would strongly recommend debugging your code in a single threaded unit test if possible, then using your by now tested code in the main program. ;)

PetriW
Re you second point: That doesn't much help if the debugger is not responding, because the bug is in the IDE, not in the debugged code. Is Delphi 2009 really better in that regard? Does F7 work everytime when debugging threads?
mghie
Re you last point: That doesn't help when you try to find problems in the interaction between threads. This is something the IDE should be rock-solid at, otherwise it's just not a professional tool. Not to speak about the nightmare that is remote debugging...
mghie
Well, I wrote a task pool in delphi 2009 with some quite extensive debugging involved and I didn't have any lock-ups. I write my multi threaded code different now though too so that might have been the reason. I'd try the D2009 trial on some code and see if it works well for you!
PetriW
Also, regarding the second point. Windows XP have some global lock in text painting if you have asian fonts installed which slows the OS to a crawl if you're unlucky. Vista fixed that which made the upgrade a huge blessing for me, but he didn't seem to have that problem. ;)
PetriW
+2  A: 

When the application itself has not deadlocked, try to be very aware of which thread you're in. Keep the thread list up in the debugger, and consider using named threads.

There are times when it will be impossible to interactively debug an application which itself deadlocks. When this happens, you can use tools such as WinDbg and Adplus in order to work with memory dumps. Yes, this is a lot harder than using the interactive debugger, but it beats having no debugger at all. There are sample applications, demos, and instructions, on Tess Ferrandez's blog. I would start with this page. The labs are .NET-centric, but don't let that keep you away; the ideas are the same.

Craig Stuntz
+1  A: 

When I want to debug a multithreaded operation I often use a log file (that I analyse after the application has run) instead of the interactive Debugger.

For example with the function 'OutputDebugString'. The output comes in the event log of Delphi. If you start your program outside of Delphi, you can use DebugView from SysInternals to display the log. Take care to add the Thread-ID to each output (GetCurrentThreadID). Be aware that there could be a thread switch just before writing to the log. But at places where several threads interact you will probably have a critical session (or another synchronization object) so that it should be a problem.

Name
A: 

Another Idea that I have never tried because I've just thought about it: if you are interested in debugging one thread and just want to avoid being disturbed by the other threads, it might be possible to suspend some threads temporaly.

Process Explorer from SysInternals offers a possibility to suspend and resume threads (in the tab called "Threads" in the properties of a process). But as I said I've never tested it until now.

Name