0

In my current C++ project I am using visual studio 2019. The output binary sat target.exe is used as a service and is created using sc.exe create command.

When we run this service it crashes immediately. So I need to debug this service. I was trying to use attach process but the service is getting crashed immediately. For a workaround I modify the code and add a 1 minute sleep in code. So now service is crashing after 1 minute and mean while I am able to attach the process. Now when service crashes, the vs output window only displaying

The program '[17396] target.exe' has exited with code -1073741819 (0xc0000005) 'Access violation'.

How can I debug this service and get the back-trace. I have found one debug setting Just My code and already disabled it but has no effect. Also enabled settings to break for all exceptions.

Note Running the binary directly gives the below error Error when debugging directly

  • Search for "AeDebug" registry key. The functionality behind it allows you to start a debugger when a process with given name is started. – Dialecticus Apr 19 '23 at 14:27
  • Sorry, scratch that, I remembered it wrong. It is actually "Image File Execution Options" to debug a service from start. – Dialecticus Apr 19 '23 at 14:49
  • The way I do this is to have both a `ServiceMain` for when the app is being used as a service and `_tmain` for when I want to debug or run the app from the command line. – user20716902 Apr 19 '23 at 15:21
  • @user20716902 Thanks for suggestion. The code is already using _tmain and was calling ServiceBase::Run(). After trying some changes I am able to run it as stand alone program. – Rakesh Mehta Apr 24 '23 at 06:29
  • @RakeshMehta Hi Rakesh, if you found a solution, you can post the detailed steps as an answer, this will help others who meet the similar issue. :) – Bowman Zhu-MSFT May 09 '23 at 02:32

0 Answers0