Ask Learn
Preview
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign inThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
There are times that you need to debug the startup code for an application, but something else is launching the application. Classic examples might be services or setup custom actions. Luckily, the OS team came up with a way to debug these problems: 'Image File Execution Options' debugging. Junfeng Zhang blogged about this a while back. Today, I wanted to talk in more detail about how to use Image File Execution Options with Visual Studio, and a bit more details about how it works.
Setup:
Here is a sample registry script to do this:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\sample.exe]
"Debugger"="vsjitdebugger.exe"
MSDN gives a good explanation for how to set this up.
The operating system implements this feature inside the user-mode part of CreateProcess. What happens is that after the operating system determines what executable is going to be started it checks the registry key for a debugger. If it finds one, it will launch the debugger instead of the application. The only way to skip this is to call CreateProcess with DEBUG_PROCESS. The debugger is then expected to launch the original application again, but this time under a debugger.
This has some very interesting implications:
Visual Studio 7.x had very basic support for image file execution options:
VS 2005 got rid of most of these. What is left:
In VS 2005, the other thing to be careful of is that debugger will guess what kind of code to debug by looking at the exe, so if you have a native exe which loads managed code, and you want to debug the managed code, make sure that you check the 'Manually choose the debug engines' checkbox when the Just-In-Time debugger dialog appears.
Anonymous
February 23, 2005
> To debug services or other 'session 0' processes, someone must be logged onto the console.
Could you explain the reason for this limitation?
Anonymous
February 25, 2005
Sure. We always show the UI in the same session that the crash occurred in. If no one is logged into that session, then we can't show UI.
Anonymous
February 16, 2006
The comment has been removed
Anonymous
April 04, 2006
I have been stumped from time to time on how to attach VS debuggers to a process on process startup....
Anonymous
February 08, 2007
Every now and than while debugging I need to either determine when a dll/module is loaded or need to
Anonymous
February 08, 2007
Every now and than while debugging I need to either determine when a dll/module is loaded or need to
Anonymous
July 18, 2007
PingBack from http://www.debugtricks.com/?p=15
Anonymous
September 12, 2008
Sometimes you need to debug a process, and you need to attach the debugger right away, but you cannot
Anonymous
September 12, 2008
PingBack from http://hoursfunnywallpaper.cn/?p=5949
Anonymous
September 12, 2008
PingBack from http://www.easycoded.com/attaching-a-debugger-at-startup/
Anonymous
September 12, 2008
PingBack from http://housesfunnywallpaper.cn/?p=5516
Anonymous
September 12, 2008
PingBack from http://informationsfunnywallpaper.cn/?p=5134
Anonymous
September 14, 2008
PingBack from http://www.ditii.com/2008/09/15/attaching-a-debugger-at-startup/
Anonymous
November 26, 2008
PingBack from http://www.binary-auditing.com/?p=24
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign in