能力值:
( LV2,RANK:10 )
|
-
-
2 楼
这么巧啊,我也遇到硬件断点的问题,遇到异常的时候ContinueDebugEvent 用DBG_EXCEPTION_NOT_HANDLED 应该就可以了。
我是新兵,发不了贴,借你的地方用下,楼主别怪阿,呵呵。
我的问题是硬件断点有效了,但是只要程序一经过硬件端点,马上断个不停,不只断了一次。
代码如下
#include "stdafx.h"
#include <windows.h>
#include <Tlhelp32.h>
#include <stdio.h>
#include <iostream>
#define PRO_TEST_ADDR 0x44D944
#define PRO_DR0_DATA 0x401
int _tmain(int argc, _TCHAR* argv[])
{
HWND hProWnd;
DWORD dwProID;
HANDLE hProHandle;
HANDLE hThreadHandle;
DWORD dwTheadID;
hProWnd = FindWindow(NULL,"Form1");
if (!hProWnd ){
printf("查找窗体句柄失败\n");
return 0;
}
dwTheadID = GetWindowThreadProcessId(hProWnd, &dwProID);
if (!dwTheadID){
printf("获取进程ID失败\n");
return 0;
}
hThreadHandle = OpenThread( THREAD_ALL_ACCESS, FALSE, dwTheadID );
if(!hThreadHandle){
printf("获取线程句柄失败\n");
return 0;
}
hProHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE , dwProID );
if (!hProHandle){
printf("打开进程句柄失败\n");
return 0;
}
if (!DebugActiveProcess(dwProID)){
printf("附加调试失败\n");
return 0;
}
DEBUG_EVENT DebugEv;
DWORD dwContinueStatus;
while (TRUE){
if (WaitForDebugEvent(&DebugEv , INFINITE)){
dwContinueStatus = DBG_EXCEPTION_NOT_HANDLED;
switch(DebugEv.dwDebugEventCode){
case EXCEPTION_DEBUG_EVENT:
{
switch( DebugEv.u.Exception.ExceptionRecord.ExceptionCode){
case EXCEPTION_SINGLE_STEP:
{
dwContinueStatus = DBG_CONTINUE;
printf(" 硬件端点\n");
break;
}
}
break;
}
case EXIT_PROCESS_DEBUG_EVENT:
{
return 0;
break;
}
case CREATE_PROCESS_DEBUG_EVENT:
{
SuspendThread(hThreadHandle);
CONTEXT Regs = {0};
Regs.ContextFlags = CONTEXT_FULL | CONTEXT_DEBUG_REGISTERS;
GetThreadContext(hThreadHandle, &Regs);
Regs.Dr0 = PRO_TEST_ADDR ;
Regs.Dr7 = PRO_DR0_DATA ;
SetThreadContext ( hThreadHandle ,&Regs );
ResumeThread(hThreadHandle);
break;
}
}
ContinueDebugEvent(DebugEv.dwProcessId, DebugEv.dwThreadId, dwContinueStatus);
}
}
return 0;
}
|
能力值:
( LV2,RANK:10 )
|
-
-
3 楼
我也用过这个.DBG_EXCEPTION_NOT_HANDLED 但一直不停的出来.
到后来都卡在这里了.
|
能力值:
( LV12,RANK:470 )
|
-
-
4 楼
你在论坛搜索下DebugActiveProcess
貌似某个帖子里面说了CONTEXT_DEBUG_REGISTERS的问题
|
能力值:
( LV2,RANK:10 )
|
-
-
5 楼
找到原因了.
EXCEPTION_ACCESS_VIOLATION异常时.
查看u.Exception.ExceptionRecord.ExceptionAddress看是哪个地址读写访问出错.
用OD看出错地址就知道是哪个函数了.
谢谢各位.
|
|
|