Debugging Win32 Services

Started by
1 comment, last by daerid 21 years, 8 months ago
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]
daerid@gmail.com
Advertisement
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]
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
(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.

This topic is closed to new replies.

Advertisement