A Debugging Approach to OutputDebugString

Using OutputDebugString is a common debugging technique for user mode debugging. It is easy but quite useful if you are debugging services or trouble shooting loader problem. #define WIN32_LEAN_AND_MEAN #include <Windows.h> int __cdecl main() {   OutputDebugStringA(“Hello, world! (first chance)\n”);   OutputDebugStringW(L”Hello, world! (second chance)\n”); } When you debug this demo application using Visual Studio, you would see the text messages from the Output window: And if you…


Debugging Tips for Multi-Threaded Application

Multi-threaded applications are error-prone and hard to debug, so it’s worth a dedicated topic. I will try to maintain a list of tips for debugging multi-threaded application using Visual Studio and WinDBG. Below is a trivial multi-threaded application which will be used as an example: #define WIN32_LEAN_AND_MEAN #include <Windows.h> DWORD WINAPI ThreadProc(LPVOID lpParameter) {   return 0; // add breakpoint here} int __cdecl main() {   HANDLE hThread = CreateThread(NULL, 4096, ThreadProc, NULL, 0, NULL);   if(hThread)   {…


Visual Studio Debugger or WinDBG?

Microsoft has provided a number of debuggers. Visual Studio Debugger would be the most widely known one, while there is a less known tool set called Debugging Tools for Windows which is available for free. Even inside Microsoft, there were questions around why having so many debuggers, and which one to use. A quick answer is,…


Data Breakpoints

The Visual Studio debugger supports a kind of breakpoint called Data Breakpoint, sometimes it is also called watchpoint. Data breakpoint is architecture dependant, as it requires hardware support provided by CPU. For x86, this will be the DR (Debug Register). The following code demonstrates how to use the x86 debug register by implementing a very simple native debugger. #define WIN32_LEAN_AND_MEAN #include <Windows.h> #include <stdio.h>…

2

Hello, world…

Yet another Hello World… Well, my name is Reiley Yang. I’m a developer working on the Visual Studio debugger. I would like to use this technical blog to share my understanding of debuggers. Previously I have also been working on the C++ libraries (ATL, CRT, MFC, STL) and compiler front-end, so I will probably also…