VirtualBox

Ticket #2252: dbg.cpp

File dbg.cpp, 1.3 KB (added by Tim Sobolev, 16 years ago)

Source file to test issue (you have to compile without optimization)

Line 
1#include "windows.h"
2#include <stdio.h>
3
4BOOL SetBreakPoint (DWORD dwAddress)
5{
6 CONTEXT ct;
7 HANDLE hThread = GetCurrentThread ();
8
9 ct.ContextFlags = CONTEXT_DEBUG_REGISTERS;
10 if (!GetThreadContext (hThread, &ct)) return (FALSE);
11
12 ct.Dr0 = dwAddress;
13 ct.Dr6 = 0;
14 ct.Dr7 = (ct.Dr7 & 0xFFF0FFFF) | 0x101;
15
16 return (SetThreadContext (hThread, &ct));
17}
18
19void TestCall2 ()
20{
21 printf ("\r\nTest Call 2 - Start\r\n");
22 printf ("\r\nTest Call 2 - End\r\n");
23}
24
25void TestCall1 ()
26{
27 printf ("\r\nTest Call 1 - Start\r\n");
28 TestCall2 ();
29 printf ("\r\nTest Call 1 - End\r\n");
30}
31
32LONG WINAPI MyVectoredHandler (PEXCEPTION_POINTERS ExceptionInfo)
33{
34 if (ExceptionInfo->ContextRecord->Dr6 & 1)
35 {
36 ExceptionInfo->ContextRecord->Dr6 = 0;
37 ExceptionInfo->ContextRecord->Dr7 &= 0xFFF0FFFE;
38 {
39 CHAR buffer[256];
40 wsprintf (buffer, "0x%.8x", ExceptionInfo->ContextRecord->Eip);
41 MessageBox (NULL, buffer, "title", MB_OK);
42 }
43
44 return (EXCEPTION_CONTINUE_EXECUTION);
45 }
46
47 return (EXCEPTION_CONTINUE_SEARCH);
48}
49
50int main (int argc, char *argv[])
51{
52 static PVOID pv;
53
54 pv = AddVectoredExceptionHandler (1, MyVectoredHandler);
55 SetBreakPoint ((DWORD) TestCall2);
56 TestCall1 ();
57 RemoveVectoredExceptionHandler (pv);
58
59 return (0);
60}

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy