Here are the steps I use to debug an NT service that was created with Delphi 6. While this works for me, there may be room for optimization.
- Our applications differentiate between a service and server version by conditional define. If you do the same thing, be sure to remember to compile the server with your "SERVICE" directive in Project | Options
- In Project Options | Linker, check the options for "Inculde TD32 debug info" and "Include Remote Debug Symbols"
- Do a full build on the server
- Register and install the service (e.g. "mysrv /regserver" and "mysrv /install") . The regserver part is needed if your serivce is a COM service.
- Set breakpoints where you want them in the server code
- Open up the Services Control Panel applet
- Select the server in the applet, and press Start
- *VERY QUICKLY*, go back to Delphi and select Run | Attach Process, select the service executable (e.g. MySrv) and press Attach
- You may get a CPU view in the Delphi IDE at this point. If so, press F9 again.
- You should be able to run a client now and have the breakpoints be respected. You may be presented with the CPU view when the breakpoint is tripped. Just go to the source window, and everything should work as normal.
NOTE: The reason for the CPU view is due to a MS problem in ntdll.dll. For some reason, they shipped Win2k and above with a hard breakpoint in the file. I used
this Delphi expert, and things worked much better. You may need this file in order to get debugging working. Then again, you might not. ;)