Is there a way to debug completely a windows service with Delphi?
相关问题
- Is there a Delphi 5 component that can handle .png
- Is there a way to install Delphi 2010 on Windows 2
- Pass custom debug information to Microsoft bot fra
- Is TWebBrowser dependant on IE version?
- iOS objective-c object: When to use release and wh
相关文章
- Service层和Dao层一定要对应吗?
- k8s 访问Pod 时好时坏
- XCopy or MOVE do not work when a WCF Service runs
- How do I get to see DbgPrint output from my kernel
- Best way to implement MVVM bindings (View <-> V
- Async task does not work properly (doInBackground
- Advanced profiling is unavailable for the selected
- Windows EventLog: How fast are operations with it?
You can use unitDebugService.pas from
Colin Wilson's NT Low Level Utilities(page is gone, available in the wayback machine)and then in the DPR:
This way you can run from within Delphi with debugging (by setting the project Debugger Parameters), use the EXE as a service, or run from the commandline with the
-DEBUG
switch, and .Yes there is.
In your dpr:
DebugService is a procedure that creates a debug form, a service control thread and kicks off everything by calling Forms.Application.Run.
You can compare the service control thread with the Windows' SCM (Service Control Manager), the debug form with an application that talks to the SCM (such as the services.msc) to start and stop services. The service should also have its own thread (service thread) to respond to control codes coming in from the SCM or our service control thread and one or many more separate threads to do its actual work. You want separate threads for the actual work (instead of coding it in the event handlers of your TService descendant) to ensure that the thread in which the TService itself runs is always free to respond to control codes from the SCM and you can still stop and start the service even when per chance a/the worker thread is frozen.
This approach allows you to debug the service app code as well, but involves a fair amount of code and placing a couple of hooks into windows api functions to work properly. Too much to show here at short notice. Maybe I'll write it up in an article some day.
In the mean time, if you don't want to code it all yourself you have two options. Either go with a library such as SVCOM or the one mentioned by Mick which do it all for you, or when in debug mode by-pass the service code all together and "simply" start your service as a "normal" forms application. You will have to disentangle the real functionality of your service from your TService descendant's code/event handlers, but that is something I'd recommend anyway for the reasons mentioned above.
Use Run -> Attach to process. This way you can debug a service without doing any changes to its code. The only tricky part maybe debugging the service start code, because attaching may require some time, and the start must happen in 30s (although you can tweak Windows to allow a longer time). You can use a delay (sleep...) to allow you to attach in time, or if you just need to see what happens you can use OutputDebugString() to print to the debug output (use Delphi Event View to see it).
It's actually quite easy. Just use the standard DEBUG compiler directive to start the service as a console application instead of a service.
[..]
Yes, there is: Debugging services: an easy way
Then you only should solve this problem.
Basically, to debug a Win2 service, there are few ways:
If you for some reason has only CPU view of your service after starting debugging - this means that Delphi's debugger can't find debug information for your service. That is a different problem and you should search solution for it.
Usually, you need to do: