Archived

This topic is now archived and is closed to further replies.

Debugging Win32 Services

This topic is 5602 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Trying to debug services has always been a pain for me. But I found out that if you stick a hard breakpoint in the code somewhere (i.e: __asm { 0x03 } ), the service'll stop at it and ask you if you want to debug the program. Assuming that a) it's the debug build, and b) you have the project open in Visual Studio, it should open up that line of code in VS, and you can step through the instance that was started by the Win32 service manager! This has helped me a great deal in finding out why when testing a program it'd work fine, but after installing it as a service and trying to start it, it crashes. Just thought I'd share the wealth :D [edited by - daerid on August 15, 2002 8:02:05 PM]

Share this post


Link to post
Share on other sites
Have you seen these? ms-help://MS.VSCC/MS.MSDNVS/dllproc/services_8nqd.htm and ms-help://MS.VSCC/MS.MSDNVS/vsdebug/html/vxtskLaunchingDebuggerAutomatically.htm

EDIT: It seems the GD forum software does strange things to anchor tags with other protocol specifiers than HTTP or FTP. It means those links arent clickable.


"It is precisely because it is fashionable for Americans to know no science, even though they may be well educated otherwise, that they so easily fall prey to nonsense. They thus become part of the armies of the night, the purveyors of nitwittery, the retailers of intellectual junk food, the feeders on mental cardboard, for their ignorance keeps them from distinguishing nectar from sewage."
Isaac Asimov

[edited by - Arild Fines on August 16, 2002 4:30:47 AM]

Share this post


Link to post
Share on other sites
(All information I write below is described in previous posts and linked articles, but I thought a summary could be good)

- Unless you need to debug during startup I recommend attaching to the process from visual studio (make sure have checked "show system processes").
- If you need to debug during startup (and can modify the source code) it''s probably easiest to put a call to DebugBreak() early in your code and make sure you have "interact with desktop" turned on for the service. This should launch the debugger dialog. DebugBreak() will do int3 on x86, but DebugBreak() will work on other platforms as well.
- Another way is to specify a debugger under Image Execution Options, but it''s a bit more complex and you can in most cases get going with any of the first two alternatives.

Share this post


Link to post
Share on other sites