Skip to content

Commit a88f260

Browse files
mmoreartyMike Morearty
authored andcommitted
rename the class
1 parent 455966e commit a88f260

File tree

2 files changed

+122
-122
lines changed

2 files changed

+122
-122
lines changed
Lines changed: 86 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,86 @@
1-
// Copyright (c) 2000 Mike Morearty <mike@morearty.com>
2-
// Original source and docs: http://www.morearty.com/code/breakpoint
3-
4-
#include <windows.h>
5-
#include <assert.h>
6-
#include "breakpoint.h"
7-
8-
#ifdef _DEBUG
9-
10-
void CBreakpoint::Set(void* address, int len, Condition when)
11-
{
12-
// make sure this breakpoint isn't already set
13-
assert(m_index == -1);
14-
15-
CONTEXT cxt;
16-
HANDLE thisThread = GetCurrentThread();
17-
18-
switch (len)
19-
{
20-
case 1: len = 0; break;
21-
case 2: len = 1; break;
22-
case 4: len = 3; break;
23-
default: assert(false); // invalid length
24-
}
25-
26-
// The only registers we care about are the debug registers
27-
cxt.ContextFlags = CONTEXT_DEBUG_REGISTERS;
28-
29-
// Read the register values
30-
if (!GetThreadContext(thisThread, &cxt))
31-
assert(false);
32-
33-
// Find an available hardware register
34-
for (m_index = 0; m_index < 4; ++m_index)
35-
{
36-
if ((cxt.Dr7 & (1 << (m_index*2))) == 0)
37-
break;
38-
}
39-
assert(m_index < 4); // All hardware breakpoint registers are already being used
40-
41-
switch (m_index)
42-
{
43-
case 0: cxt.Dr0 = (DWORD) address; break;
44-
case 1: cxt.Dr1 = (DWORD) address; break;
45-
case 2: cxt.Dr2 = (DWORD) address; break;
46-
case 3: cxt.Dr3 = (DWORD) address; break;
47-
default: assert(false); // m_index has bogus value
48-
}
49-
50-
SetBits(cxt.Dr7, 16 + (m_index*4), 2, when);
51-
SetBits(cxt.Dr7, 18 + (m_index*4), 2, len);
52-
SetBits(cxt.Dr7, m_index*2, 1, 1);
53-
54-
// Write out the new debug registers
55-
if (!SetThreadContext(thisThread, &cxt))
56-
assert(false);
57-
}
58-
59-
60-
void CBreakpoint::Clear()
61-
{
62-
if (m_index != -1)
63-
{
64-
CONTEXT cxt;
65-
HANDLE thisThread = GetCurrentThread();
66-
67-
// The only registers we care about are the debug registers
68-
cxt.ContextFlags = CONTEXT_DEBUG_REGISTERS;
69-
70-
// Read the register values
71-
if (!GetThreadContext(thisThread, &cxt))
72-
assert(false);
73-
74-
// Zero out the debug register settings for this breakpoint
75-
assert(m_index >= 0 && m_index < 4); // m_index has bogus value
76-
SetBits(cxt.Dr7, m_index*2, 1, 0);
77-
78-
// Write out the new debug registers
79-
if (!SetThreadContext(thisThread, &cxt))
80-
assert(false);
81-
82-
m_index = -1;
83-
}
84-
}
85-
86-
#endif // _DEBUG
1+
// Copyright (c) 2000 Mike Morearty <mike@morearty.com>
2+
// Original source and docs: http://www.morearty.com/code/breakpoint
3+
4+
#include <windows.h>
5+
#include <assert.h>
6+
#include "hardwarebp.h"
7+
8+
#ifdef _DEBUG
9+
10+
void HardwareBreakpoint::Set(void* address, int len, Condition when)
11+
{
12+
// make sure this breakpoint isn't already set
13+
assert(m_index == -1);
14+
15+
CONTEXT cxt;
16+
HANDLE thisThread = GetCurrentThread();
17+
18+
switch (len)
19+
{
20+
case 1: len = 0; break;
21+
case 2: len = 1; break;
22+
case 4: len = 3; break;
23+
default: assert(false); // invalid length
24+
}
25+
26+
// The only registers we care about are the debug registers
27+
cxt.ContextFlags = CONTEXT_DEBUG_REGISTERS;
28+
29+
// Read the register values
30+
if (!GetThreadContext(thisThread, &cxt))
31+
assert(false);
32+
33+
// Find an available hardware register
34+
for (m_index = 0; m_index < 4; ++m_index)
35+
{
36+
if ((cxt.Dr7 & (1 << (m_index*2))) == 0)
37+
break;
38+
}
39+
assert(m_index < 4); // All hardware breakpoint registers are already being used
40+
41+
switch (m_index)
42+
{
43+
case 0: cxt.Dr0 = (DWORD) address; break;
44+
case 1: cxt.Dr1 = (DWORD) address; break;
45+
case 2: cxt.Dr2 = (DWORD) address; break;
46+
case 3: cxt.Dr3 = (DWORD) address; break;
47+
default: assert(false); // m_index has bogus value
48+
}
49+
50+
SetBits(cxt.Dr7, 16 + (m_index*4), 2, when);
51+
SetBits(cxt.Dr7, 18 + (m_index*4), 2, len);
52+
SetBits(cxt.Dr7, m_index*2, 1, 1);
53+
54+
// Write out the new debug registers
55+
if (!SetThreadContext(thisThread, &cxt))
56+
assert(false);
57+
}
58+
59+
60+
void HardwareBreakpoint::Clear()
61+
{
62+
if (m_index != -1)
63+
{
64+
CONTEXT cxt;
65+
HANDLE thisThread = GetCurrentThread();
66+
67+
// The only registers we care about are the debug registers
68+
cxt.ContextFlags = CONTEXT_DEBUG_REGISTERS;
69+
70+
// Read the register values
71+
if (!GetThreadContext(thisThread, &cxt))
72+
assert(false);
73+
74+
// Zero out the debug register settings for this breakpoint
75+
assert(m_index >= 0 && m_index < 4); // m_index has bogus value
76+
SetBits(cxt.Dr7, m_index*2, 1, 0);
77+
78+
// Write out the new debug registers
79+
if (!SetThreadContext(thisThread, &cxt))
80+
assert(false);
81+
82+
m_index = -1;
83+
}
84+
}
85+
86+
#endif // _DEBUG
Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
1-
// Copyright (c) 2000 Mike Morearty <mike@morearty.com>
2-
// Original source and docs: http://www.morearty.com/code/breakpoint
3-
4-
#ifndef _BREAKPOINT_H_
5-
#define _BREAKPOINT_H_
6-
7-
#ifdef _DEBUG
8-
9-
class CBreakpoint
10-
{
11-
public:
12-
CBreakpoint() { m_index = -1; }
13-
~CBreakpoint() { Clear(); }
14-
15-
// The enum values correspond to the values used by the Intel Pentium,
16-
// so don't change them!
17-
enum Condition { Write = 1, Read /* or write! */ = 3 };
18-
19-
void Set(void* address, int len /* 1, 2, or 4 */, Condition when);
20-
void Clear();
21-
22-
protected:
23-
24-
inline void SetBits(unsigned long& dw, int lowBit, int bits, int newValue)
25-
{
26-
int mask = (1 << bits) - 1; // e.g. 1 becomes 0001, 2 becomes 0011, 3 becomes 0111
27-
28-
dw = (dw & ~(mask << lowBit)) | (newValue << lowBit);
29-
}
30-
31-
int m_index; // -1 means not set; 0-3 means we've set that hardware bp
32-
};
33-
34-
#endif // _DEBUG
35-
36-
#endif // _BREAKPOINT_H_
1+
// Copyright (c) 2000 Mike Morearty <mike@morearty.com>
2+
// Original source and docs: http://www.morearty.com/code/breakpoint
3+
4+
#ifndef _HARDWAREBP_H_
5+
#define _HARDWAREBP_H_
6+
7+
#ifdef _DEBUG
8+
9+
class HardwareBreakpoint
10+
{
11+
public:
12+
HardwareBreakpoint() { m_index = -1; }
13+
~HardwareBreakpoint() { Clear(); }
14+
15+
// The enum values correspond to the values used by the Intel Pentium,
16+
// so don't change them!
17+
enum Condition { Write = 1, Read /* or write! */ = 3 };
18+
19+
void Set(void* address, int len /* 1, 2, or 4 */, Condition when);
20+
void Clear();
21+
22+
protected:
23+
24+
inline void SetBits(unsigned long& dw, int lowBit, int bits, int newValue)
25+
{
26+
int mask = (1 << bits) - 1; // e.g. 1 becomes 0001, 2 becomes 0011, 3 becomes 0111
27+
28+
dw = (dw & ~(mask << lowBit)) | (newValue << lowBit);
29+
}
30+
31+
int m_index; // -1 means not set; 0-3 means we've set that hardware bp
32+
};
33+
34+
#endif // _DEBUG
35+
36+
#endif // _HARDWAREBP_H_

0 commit comments

Comments
 (0)