Click here to Skip to main content
15,886,362 members
Articles / Programming Languages / C

Write Your Own Debugger to Handle Breakpoints

Rate me:
Please Sign up or sign in to vote.
4.55/5 (11 votes)
17 May 2011CPOL4 min read 50.8K   1.5K   47  
Basic debugger, Breakpoints, OutputDebugString
// Debuggee.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<Windows.h>
#include<comdef.h>

int _tmain(int argc, _TCHAR* argv[])
{
	MessageBoxA(0,"Debuggee started","placing break point",0);

	//find IP  (mov eax,eip :invalid opcode)
	UINT EIP=0;
	_asm 
	{
		call f
		jmp finish

f:		pop eax
		mov EIP,eax
		push eax
		ret
finish:
	}
	EIP+=50;

	BYTE *b=(BYTE*)EIP;
	for(int i=0;i<100;i++)
		printf("%x : %x \n",EIP+i,b[i]);

	::DebugBreak();  //notice that instruction 0xcc is placed here (which is Interrupt 3), the debug memory dump window will not show this

	::OutputDebugString(_bstr_t::bstr_t("debug string"));
	MessageBoxA(0,"Debuggee ending","",0);
	return 0;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Instructor / Trainer
India India
Hi,
I have been working with computers since my eight grade, programming the ZX Spectrum. I have always had an interest in assembly language and computer theory (and is still the reason for taking tons of online courses), actively code using C/C++ on Windows (using VS) and Linux (using QT).

I also provide training on data structures, algorithms, parallel patterns library , Graphics (DX11), GPGPUs (DX11-CS,AMP) and programming for performance on x86.
Feel free to call me at 0091-9823018914 (UTC +5:30)



(All views expressed here do not reflect the views of my employer).

Comments and Discussions