Click here to Skip to main content
15,896,417 members
Articles / Programming Languages / C++

Extending windbg with Page Fault Breakpoints

Rate me:
Please Sign up or sign in to vote.
4.93/5 (16 votes)
1 May 2011Ms-PL6 min read 78.9K   1.8K   43  
Take advantage of the memory page access flag, and set a new kind of breakpoint
// ----------------------------------------------------------------------------------------------
// Copyright (c) Mattias H�gstr�m.
// ----------------------------------------------------------------------------------------------
// This source code is subject to terms and conditions of the Microsoft Public License. A 
// copy of the license can be found in the License.html file at the root of this distribution. 
// If you cannot locate the Microsoft Public License, please send an email to 
// dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound 
// by the terms of the Microsoft Public License.
// ----------------------------------------------------------------------------------------------
// You must not remove this notice, or any other, from this software.
// ----------------------------------------------------------------------------------------------

#include "stdafx.h"
#include <string>

using namespace std;


typedef struct {
	char buffer[4];
	char maxLen;
	char origValue;
	char stop;
} SampleStruct;

SampleStruct data = {0};

void SetLimits()
{
	memset(&data, 0, sizeof(data));
	data.maxLen = sizeof(data.buffer) - 1;
}

void SetValue(char amount)
{
	data.origValue = amount;
}

void Convert()
{
	// Function expects values 0-127
	// Negative numbers will be proceeded by a minus (-)
	// and will overwrite maxLen  memory
	sprintf(data.buffer, "%d", data.origValue);
}

string GetValue()
{
	return data.buffer;
}

int ValidateDataIntegrity()
{
	int result = 0;
	if (!(strlen(data.buffer) < sizeof(data.buffer)))
		result |= 1;
	if (!(data.maxLen == (sizeof(data.buffer) - 1)))
		result |= 2;
	if (strlen(data.buffer) != 0)
	{
		int a1 = data.origValue;
		int a2 = atoi(data.buffer);
		if (a1 != a2)
			result |= 4;
	}
	return result;
}

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 Microsoft Public License (Ms-PL)


Written By
Architect Visma Software AB
Sweden Sweden
Mattias works at Visma, a leading Nordic ERP solution provider. He has good knowledge in C++/.Net development, test tool development, and debugging. His great passion is memory dump analysis. He likes giving talks and courses.

Comments and Discussions