How to debug a windows service with Delphi?

后端 未结 6 1329
轻奢々
轻奢々 2020-12-05 02:48

Is there a way to debug completely a windows service with Delphi?

6条回答
  •  广开言路
    2020-12-05 03:30

    I've tried this, but only appears the cpu window with assembly codes.

    Then you only should solve this problem.

    Basically, to debug a Win2 service, there are few ways:

    • Use "Attach to process" command to attach debugger to already running service. You may insert startup delays to have time to attach debugger, if you need to attach at the very beginning. However, you would also have to tweak the system to increase service timeouts.
    • Use "Image File Execution Options" registry key to force-run Delphi's debugger at service startup. The same considerations about system timeouts apply.
    • Temporary convert service into usual application and run it under debugger normally. You may re-launch IDE under different user account to gain more priviledges for the "service".

    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:

    1. Make sure that output folder for your service application is set to folder from which it will be loaded by the system. I.e. if your service is located in C:\Windows\System32 - then set output folder to C:\Windows\System32. Do not copy .exe file elsewhere from your output folder. For 64 systems you may try alias (sysnative/SysWOW64) or real name. I think it's best to set output path to project's folder and re-register service to be loaded from project folder.
    2. (Optional) Set output path for DCU into the same folder as .exe file.
    3. Delete all of your DCU files.
    4. Make sure to enable debug options on "Compiler" page in project options.
    5. (Optional) Additionally you may also include TD32/RSM/MAP options on "Linker" page.
    6. Make sure there is no IDE expert/extension, which may modify .exe file, debug information or file modification date for these files.
    7. Make sure there is no old files (DCU/exe) in other locations.
    8. Make a full rebuild (Project/Build all).
    9. Run your service.

提交回复
热议问题