Delphi中更好的多线程调试

时间:2021-07-23 21:00:52

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?

从答案到另一个关于Delphi IDE中的错误的问题,有没有人知道是否有办法改进IDE的多线程调试功能,或者如果没有,至少为什么它有时会如此糟糕?

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.

当程序中有多个线程时,使用F7或F8单步执行代码通常会导致非常长的暂停,或者整个IDE只会锁定。当您离开或输入方法或程序时,这一点尤为明显。对于单线程应用程序,调试器似乎总是很好。

PS. The version I'm using is 2007

PS。我使用的版本是2007

5 个解决方案

#1


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

根据我的经验,使用Vista和Delphi 2009的多线程调试比使用Delphi 2007的XP要好得多。

First, the ide is significantly more stable.

首先,ide明显更稳定。

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

其次,在vista上的Delphi 2009中,调试器可以向您显示发生死锁的位置。

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. ;)

如果你必须使用Delphi 2007,我强烈建议在可能的情况下在单线程单元测试中调试你的代码,然后在主程序中使用你现在测试过的代码。 ;)

#2


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.

有时无法以交互方式调试本身死锁的应用程序。发生这种情况时,您可以使用WinDbg和Adplus等工具来处理内存转储。是的,这比使用交互式调试器要困难得多,但它根本没有调试器。在Tess Ferrandez的博客上有示例应用程序,演示和说明。我会从这个页面开始。实验室以.NET为中心,但不要让它让你远离;这些想法是一样的。

#3


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.

例如,使用函数'OutputDebugString'。输出来自Delphi的事件日志。如果您在Delphi之外启动程序,则可以使用SysInternals中的DebugView来显示日志。注意将Thread-ID添加到每个输出(GetCurrentThreadID)。请注意,在写入日志之前可能会有一个线程切换。但是在多个线程交互的地方,您可能会有一个关键会话(或另一个同步对象),因此它应该是一个问题。

#4


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

是的,调试多线程应用程序是一件麻烦事。因为你经常从一个线程交换到另一个线程。

#5


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.

SysInternals的Process Explorer提供了挂起和恢复线程的可能性(在进程属性中名为“Threads”的选项卡中)。但正如我所说,我从未测试过它。

#1


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

根据我的经验,使用Vista和Delphi 2009的多线程调试比使用Delphi 2007的XP要好得多。

First, the ide is significantly more stable.

首先,ide明显更稳定。

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

其次,在vista上的Delphi 2009中,调试器可以向您显示发生死锁的位置。

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. ;)

如果你必须使用Delphi 2007,我强烈建议在可能的情况下在单线程单元测试中调试你的代码,然后在主程序中使用你现在测试过的代码。 ;)

#2


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.

有时无法以交互方式调试本身死锁的应用程序。发生这种情况时,您可以使用WinDbg和Adplus等工具来处理内存转储。是的,这比使用交互式调试器要困难得多,但它根本没有调试器。在Tess Ferrandez的博客上有示例应用程序,演示和说明。我会从这个页面开始。实验室以.NET为中心,但不要让它让你远离;这些想法是一样的。

#3


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.

例如,使用函数'OutputDebugString'。输出来自Delphi的事件日志。如果您在Delphi之外启动程序,则可以使用SysInternals中的DebugView来显示日志。注意将Thread-ID添加到每个输出(GetCurrentThreadID)。请注意,在写入日志之前可能会有一个线程切换。但是在多个线程交互的地方,您可能会有一个关键会话(或另一个同步对象),因此它应该是一个问题。

#4


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

是的,调试多线程应用程序是一件麻烦事。因为你经常从一个线程交换到另一个线程。

#5


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.

SysInternals的Process Explorer提供了挂起和恢复线程的可能性(在进程属性中名为“Threads”的选项卡中)。但正如我所说,我从未测试过它。