Browse Source

Implement breakpoint handler

pull/287/head^2
galaxyhaxz 7 years ago
parent
commit
b76156e206
  1. 38
      Source/appfat.cpp
  2. 4
      Source/appfat.h
  3. 4
      Source/dx.cpp
  4. 11
      Source/fault.cpp
  5. 1
      Source/fault.h

38
Source/appfat.cpp

@ -13,6 +13,41 @@ int cleanup_thread_id;
// }
//}
void TriggerBreak()
{
#ifdef _DEBUG
LPTOP_LEVEL_EXCEPTION_FILTER pFilter;
pFilter = SetUnhandledExceptionFilter(BreakFilter);
#ifdef USE_ASM
__asm {
int 3
}
#else
__debugbreak();
#endif
SetUnhandledExceptionFilter(pFilter);
#endif
}
#ifdef _DEBUG
LONG __stdcall BreakFilter(PEXCEPTION_POINTERS pExc)
{
if(pExc->ExceptionRecord == NULL) {
return 0;
}
if(pExc->ExceptionRecord->ExceptionCode != EXCEPTION_BREAKPOINT) {
return 0;
}
if(((BYTE *)pExc->ContextRecord->Eip)[0] == 0xCC) { // int 3
pExc->ContextRecord->Eip++;
}
return -1;
}
#endif
char *GetErrorStr(DWORD error_code)
{
DWORD upper_code;
@ -421,6 +456,9 @@ void __cdecl app_fatal(const char *pszFmt, ...)
va_start(va, pszFmt);
FreeDlg();
#ifdef _DEBUG
TriggerBreak();
#endif
if (pszFmt)
MsgBox(pszFmt, va);

4
Source/appfat.h

@ -6,6 +6,10 @@ extern char sz_error_buf[256];
extern int terminating; // weak
extern int cleanup_thread_id; // weak
void TriggerBreak();
#ifdef _DEBUG
LONG __stdcall BreakFilter(PEXCEPTION_POINTERS pExc);
#endif
char *GetErrorStr(DWORD error_code);
void TraceErrorDD(HRESULT hError, char *pszBuffer, DWORD dwMaxChars);
void TraceErrorDS(HRESULT hError, char *pszBuffer, DWORD dwMaxChars);

4
Source/dx.cpp

@ -59,7 +59,7 @@ void dx_init(HWND hWnd)
hDDVal = lpDDInterface->lpVtbl->SetCooperativeLevel(lpDDInterface, hWnd, DDSCL_NORMAL | DDSCL_ALLOWREBOOT);
#endif
if(hDDVal == DDERR_EXCLUSIVEMODEALREADYSET) {
break_exception();
TriggerBreak();
} else if(hDDVal != DD_OK) {
ErrDlg(IDD_DIALOG1, hDDVal, "C:\\Diablo\\Direct\\dx.cpp", 155);
}
@ -71,7 +71,7 @@ void dx_init(HWND hWnd)
hDDVal = lpDDInterface->lpVtbl->SetCooperativeLevel(lpDDInterface, hWnd, DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT | DDSCL_FULLSCREEN);
#endif
if(hDDVal == DDERR_EXCLUSIVEMODEALREADYSET) {
break_exception();
TriggerBreak();
} else if(hDDVal != DD_OK) {
ErrDlg(IDD_DIALOG1, hDDVal, "C:\\Src\\Diablo\\Source\\dx.cpp", 170);
}

11
Source/fault.cpp

@ -32,17 +32,6 @@ LPTOP_LEVEL_EXCEPTION_FILTER __cdecl fault_cleanup_filter()
return fault_reset_filter(&fault_unused);
}
void break_exception()
{
/*
LPTOP_LEVEL_EXCEPTION_FILTER pFilter;
pFilter = SetUnhandledExceptionFilter(TopLevelExceptionFilter);
__asm int 3
SetUnhandledExceptionFilter(pFilter);
*/
}
LONG __stdcall TopLevelExceptionFilter(PEXCEPTION_POINTERS ExceptionInfo)
{
PEXCEPTION_RECORD xcpt;

1
Source/fault.h

@ -13,7 +13,6 @@ extern LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter;
void fault_init_filter();
void fault_cleanup_filter_atexit();
LPTOP_LEVEL_EXCEPTION_FILTER __cdecl fault_cleanup_filter();
void break_exception();
LONG __stdcall TopLevelExceptionFilter(PEXCEPTION_POINTERS ExceptionInfo);
void fault_hex_format(BYTE *ptr, unsigned int numBytes);
void fault_unknown_module(LPCVOID lpAddress, LPSTR lpModuleName, int iMaxLength, int *sectionNum, int *sectionOffset);

Loading…
Cancel
Save