Sounds like a straight forward question that should have a simple answer. I bet your thinking it’s not even worthy of a blog post? At first glance, I would tend to agree. Just run your program in the debugger. Unfortunately, there are many ways of doing that and no one approach is optimal for all the debugging situations you may encounter.
Here is a list of a few ways that I know of that can be used to get into the debugger
- Start the process in the debugger (ie, windbg.exe my_program.exe)
- Start the process in the debugger using the Image File Execution Options registry keys provided by windows.
- Attach the debugger to an already running process.
- Attach a kernel debugger to a specific instance of the program you are running.
- Compile DebugBreak() call’s into your code
- Compile an Int 3 assembly instruction into your code.
- Compile conditional DebugBreak() or Int 3 calls into your code.
- Cause a controlled access violation in your code which you then step over.
It’s very possible that I’m missing several methods but at least this is a start ;).
I plan on creating a unique tutorial for each one of these approaches. The goal is to highlight the strengths and weaknesses of each approach which I have listed in order of preference (sort of). I really don’t like debugging techniques that involve modification of source code and recompilation. It’s often far faster (and easier) to get your process into a debugger and set breakpoints where appropriate.