I’ve written application in Delphi 2007, which some times hangs (not even every week, application is running 24/7). It looks like main thread gets stuck. What are the options to pinpoint the cause for this problem?
Application is written in Delphi 2007, it uses RemObjects, DBExpress with Firebird, OPC communication using COM.
Using MadExcept you can specify that the main thread is periodically checked to still process messages (with a variable timeout, which you would set to a value higher than your longest actions would take). If the main thread hangs you can thus obtain a stack trace.
See Main thread freeze checking…
I have used this with some success, it only failed when the hang was in a driver (which is probably to be expected). After beginning to suspect the driver (for an A/D conversion card) I added trace messages before and after each API call and was able to prove the driver being the culprit. Note that it will be important to immediately write messages to a file and flush the buffers in order to get reliable log data.
I have also successfully used WinDbg to attach to a hanging executable on a system without installed Delphi. This turned out to be a deadlock from not always acquiring critical sections in the same order. WinDbg helps analyse such situations by examining the thread stacks and the state of critical sections.