10

A very simple situation. I'm working on an application in Delphi 2007 which is often compiled as 'Release' but still runs under a debugger. And occasionally it will run under SilkTest too, for regression testing. While this is quite fun I want to do something special...

I want to detect if my application is running within a debugger/regression-tester and if that's the case, I want the application to know which tool is used! (Thus, when the application crashes, I could report this information in it's error report.)

Any suggestions, solutions?

2

4 Answers 4

11

You can check the parent process that started your application. With CreateToolhelp32Snapshot/Process32First/Process32Next get the parent PID (PROCESSENTRY32.th32ParentProcessID or TProcessEntry32.th32ParentProcessID) for your application PID. Then get the filename for the parent PID to compare with the applications you want to check for, like SilkTest.

Check this article for code usage.

In addition to IsDebuggerPresent and CheckRemoteDebuggerPresent, you can also query PEB.BeingDebugged (PEB is Process Environment Block, to get PEB you must query TEB, which is the Thread Enviroment Block).

4

You're probably looking for the IsDebuggerPresent function.

2
  • But will it also detect SilkTest and other testing software? Or remote debuggers? Sep 18, 2009 at 9:23
  • 1
    There is also the CheckRemoteDebuggerPresent function, which sounds like it might identify remote debuggers. I'm unfamiliar with SilkTest so I don't know whether it acts as a debugger or not. If it does, then the above will work. If not, then you will need to find another technique. Sep 18, 2009 at 9:47
1

To detect SilkTest, you could try to attach to a DLL which is used only by SilkTest in order to detect its presence. For example, if the Open Agent is attached to a process, Win32HookDll_x86.dll or Win32HookDll_amd64.dll will be present (the names can be easily found out with a tool like Process Explorer.

-1

You can also do

if DebugHook <> 0 then ...
1
  • That only works from within the Delphi IDE, not other debuggers. Also, keep in mind the application is debugged in "Release" mode, not "Debug" mode. Sep 18, 2009 at 9:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.