1
0
Fork 0

DBG+GUI: text files for error/exception codes instead of hardcoded in the source

This commit is contained in:
Mr. eXoDia 2016-06-22 14:42:54 +02:00
parent 63fb2a87fe
commit c048e1db78
17 changed files with 2390 additions and 2285 deletions

2188
bin/errordb.txt Normal file

File diff suppressed because it is too large Load Diff

70
bin/exceptiondb.txt Normal file
View File

@ -0,0 +1,70 @@
0x000006BA RPC_S_SERVER_UNAVAILABLE
0x0000071A RPC_S_CALL_CANCELLED
0x04242420 CLRDBG_NOTIFICATION_EXCEPTION_CODE
0x40000005 STATUS_SEGMENT_NOTIFICATION
0x40000015 STATUS_FATAL_APP_EXIT
0x4000001C STATUS_WX86_UNSIMULATE
0x4000001D STATUS_WX86_CONTINUE
0x4000001E STATUS_WX86_SINGLE_STEP
0x4000001F STATUS_WX86_BREAKPOINT
0x40000020 STATUS_WX86_EXCEPTION_CONTINUE
0x40000021 STATUS_WX86_EXCEPTION_LASTCHANCE
0x40000022 STATUS_WX86_EXCEPTION_CHAIN
0x40000028 STATUS_WX86_CREATEWX86TIB
0x40010003 DBG_TERMINATE_THREAD
0x40010004 DBG_TERMINATE_PROCESS
0x40010005 DBG_CONTROL_C
0x40010006 DBG_PRINTEXCEPTION_C
0x40010007 DBG_RIPEXCEPTION
0x40010008 DBG_CONTROL_BREAK
0x40010009 DBG_COMMAND_EXCEPTION
0x4001000A DBG_PRINTEXCEPTION_WIDE_C
0x406D1388 MS_VC_EXCEPTION
0x80000001 EXCEPTION_GUARD_PAGE
0x80000002 EXCEPTION_DATATYPE_MISALIGNMENT
0x80000003 EXCEPTION_BREAKPOINT
0x80000004 EXCEPTION_SINGLE_STEP
0x80000026 STATUS_LONGJUMP
0x80000029 STATUS_UNWIND_CONSOLIDATE
0x80010001 DBG_EXCEPTION_NOT_HANDLED
0xC0000005 EXCEPTION_ACCESS_VIOLATION
0xC0000006 EXCEPTION_IN_PAGE_ERROR
0xC0000008 EXCEPTION_INVALID_HANDLE
0xC000000D STATUS_INVALID_PARAMETER
0xC0000017 STATUS_NO_MEMORY
0xC000001D EXCEPTION_ILLEGAL_INSTRUCTION
0xC0000025 EXCEPTION_NONCONTINUABLE_EXCEPTION
0xC0000026 EXCEPTION_INVALID_DISPOSITION
0xC000008C EXCEPTION_ARRAY_BOUNDS_EXCEEDED
0xC000008D EXCEPTION_FLT_DENORMAL_OPERAND
0xC000008E EXCEPTION_FLT_DIVIDE_BY_ZERO
0xC000008F EXCEPTION_FLT_INEXACT_RESULT
0xC0000090 EXCEPTION_FLT_INVALID_OPERATION
0xC0000091 EXCEPTION_FLT_OVERFLOW
0xC0000092 EXCEPTION_FLT_STACK_CHECK
0xC0000093 EXCEPTION_FLT_UNDERFLOW
0xC0000094 EXCEPTION_INT_DIVIDE_BY_ZERO
0xC0000095 EXCEPTION_INT_OVERFLOW
0xC0000096 EXCEPTION_PRIV_INSTRUCTION
0xC00000FD EXCEPTION_STACK_OVERFLOW
0xC0000135 STATUS_DLL_NOT_FOUND
0xC0000138 STATUS_ORDINAL_NOT_FOUND
0xC0000139 STATUS_ENTRYPOINT_NOT_FOUND
0xC000013A STATUS_CONTROL_C_EXIT
0xC0000142 STATUS_DLL_INIT_FAILED
0xC000014A STATUS_ILLEGAL_FLOAT_CONTEXT
0xC0000194 EXCEPTION_POSSIBLE_DEADLOCK
0xC00001A5 STATUS_INVALID_EXCEPTION_HANDLER
0xC00002B4 STATUS_FLOAT_MULTIPLE_FAULTS
0xC00002B5 STATUS_FLOAT_MULTIPLE_TRAPS
0xC00002C5 STATUS_DATATYPE_MISALIGNMENT_ERROR
0xC00002C9 STATUS_REG_NAT_CONSUMPTION
0xC0000374 STATUS_HEAP_CORRUPTION
0xC0000409 STATUS_STACK_BUFFER_OVERRUN
0xC0000417 STATUS_INVALID_CRUNTIME_PARAMETER
0xC000041D STATUS_USER_CALLBACK
0xC0000420 STATUS_ASSERTION_FAILURE
0xC015000F STATUS_SXS_EARLY_DEACTIVATION
0xC0150010 STATUS_SXS_INVALID_DEACTIVATION
0xE0434352 CLR_EXCEPTION
0xE06D7363 CPP_EH_EXCEPTION

View File

@ -123,8 +123,10 @@ mkdir %RELEASEDIR%\release\translations
mkdir %RELEASEDIR%\release\x32
mkdir %RELEASEDIR%\release\x64
copy bin\x96dbg.exe %RELEASEDIR%\release\x96dbg.exe
copy bin\mnemdb.json %RELEASEDIR%\release\mnemdb.json
copy bin\x96dbg.exe %RELEASEDIR%\release\
copy bin\mnemdb.json %RELEASEDIR%\release\
copy bin\errordb.txt %RELEASEDIR%\release\
copy bin\exceptiondb.txt %RELEASEDIR%\release\
xcopy src\gui\Translations\*.qm %RELEASEDIR%\release\translations /S /Y
copy bin\x32\x32bridge.dll %RELEASEDIR%\release\x32\
copy bin\x32\x32bridge.pdb %RELEASEDIR%\release\x32\

View File

@ -582,7 +582,7 @@ typedef struct
typedef struct
{
DWORD code;
const char* name;
char name[128];
} LASTERROR;
typedef struct

View File

@ -525,7 +525,7 @@ extern "C" DLL_EXPORT bool _dbg_getregdump(REGDUMP* regdump)
Getx87StatusWordFields(& (regdump->x87StatusWordFields), regdump->regcontext.x87fpu.StatusWord);
LASTERROR lastError;
lastError.code = ThreadGetLastError(ThreadGetId(hActiveThread));
lastError.name = ErrorCodeToName(lastError.code);
strcpy_s(lastError.name, _TRUNCATE, ErrorCodeToName(lastError.code).c_str());
regdump->lastError = lastError;
return true;

View File

@ -158,8 +158,6 @@ static DWORD WINAPI timeWastedCounterThread(void* ptr)
void dbginit()
{
ExceptionCodeInit();
ErrorCodeInit();
hMemMapThread = CreateThread(nullptr, 0, memMapThread, nullptr, 0, nullptr);
hTimeWastedCounterThread = CreateThread(nullptr, 0, timeWastedCounterThread, nullptr, 0, nullptr);
}
@ -1471,11 +1469,11 @@ static void cbException(EXCEPTION_DEBUG_INFO* ExceptionData)
}
}
}
const char* exceptionName = ExceptionCodeToName(ExceptionCode);
auto exceptionName = ExceptionCodeToName(ExceptionCode);
if(ExceptionData->dwFirstChance) //first chance exception
{
if(exceptionName)
dprintf("First chance exception on " fhex " (%.8X, %s)!\n", addr, ExceptionCode, exceptionName);
if(exceptionName.size())
dprintf("First chance exception on " fhex " (%.8X, %s)!\n", addr, ExceptionCode, exceptionName.c_str());
else
dprintf("First chance exception on " fhex " (%.8X)!\n", addr, ExceptionCode);
SetNextDbgContinueStatus(DBG_EXCEPTION_NOT_HANDLED);
@ -1484,8 +1482,8 @@ static void cbException(EXCEPTION_DEBUG_INFO* ExceptionData)
}
else //lock the exception
{
if(exceptionName)
dprintf("Last chance exception on " fhex " (%.8X, %s)!\n", addr, ExceptionCode, exceptionName);
if(exceptionName.size())
dprintf("Last chance exception on " fhex " (%.8X, %s)!\n", addr, ExceptionCode, exceptionName.c_str());
else
dprintf("Last chance exception on " fhex " (%.8X)!\n", addr, ExceptionCode);
SetNextDbgContinueStatus(DBG_CONTINUE);
@ -2046,7 +2044,7 @@ static void debugLoopFunction(void* lpParameter, bool attach)
if(!fdProcessInfo)
{
fdProcessInfo = &g_pi;
dprintf("Error starting process (CreateProcess, %s)!\n", ErrorCodeToName(GetLastError()));
dprintf("Error starting process (CreateProcess, %s)!\n", ErrorCodeToName(GetLastError()).c_str());
unlock(WAITID_STOP);
return;
}

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,9 @@
#ifndef _ERROR_H
#define _ERROR_H
void ErrorCodeInit();
const char* ErrorCodeToName(unsigned int ErrorCode);
#include "_global.h"
bool ErrorCodeInit(const String & errorFile);
String ErrorCodeToName(unsigned int ErrorCode);
#endif // _ERROR_H

View File

@ -1,87 +1,45 @@
#include <unordered_map>
#include "exception.h"
#include "filehelper.h"
#include "value.h"
#include "console.h"
std::unordered_map<unsigned int, const char*> ExceptionNames;
std::unordered_map<unsigned int, String> ExceptionNames;
void ExceptionCodeInit()
bool ExceptionCodeInit(const String & exceptionFile)
{
ExceptionNames.clear();
ExceptionNames.insert(std::make_pair(0x000006BA, "RPC_S_SERVER_UNAVAILABLE"));
ExceptionNames.insert(std::make_pair(0x0000071A, "RPC_S_CALL_CANCELLED"));
ExceptionNames.insert(std::make_pair(0x04242420, "CLRDBG_NOTIFICATION_EXCEPTION_CODE"));
ExceptionNames.insert(std::make_pair(0x40000005, "STATUS_SEGMENT_NOTIFICATION"));
ExceptionNames.insert(std::make_pair(0x40000015, "STATUS_FATAL_APP_EXIT"));
ExceptionNames.insert(std::make_pair(0x4000001C, "STATUS_WX86_UNSIMULATE"));
ExceptionNames.insert(std::make_pair(0x4000001D, "STATUS_WX86_CONTINUE"));
ExceptionNames.insert(std::make_pair(0x4000001E, "STATUS_WX86_SINGLE_STEP"));
ExceptionNames.insert(std::make_pair(0x4000001F, "STATUS_WX86_BREAKPOINT"));
ExceptionNames.insert(std::make_pair(0x40000020, "STATUS_WX86_EXCEPTION_CONTINUE"));
ExceptionNames.insert(std::make_pair(0x40000021, "STATUS_WX86_EXCEPTION_LASTCHANCE"));
ExceptionNames.insert(std::make_pair(0x40000022, "STATUS_WX86_EXCEPTION_CHAIN"));
ExceptionNames.insert(std::make_pair(0x40000028, "STATUS_WX86_CREATEWX86TIB"));
ExceptionNames.insert(std::make_pair(0x40010003, "DBG_TERMINATE_THREAD"));
ExceptionNames.insert(std::make_pair(0x40010004, "DBG_TERMINATE_PROCESS"));
ExceptionNames.insert(std::make_pair(0x40010005, "DBG_CONTROL_C"));
ExceptionNames.insert(std::make_pair(0x40010006, "DBG_PRINTEXCEPTION_C"));
ExceptionNames.insert(std::make_pair(0x40010007, "DBG_RIPEXCEPTION"));
ExceptionNames.insert(std::make_pair(0x40010008, "DBG_CONTROL_BREAK"));
ExceptionNames.insert(std::make_pair(0x40010009, "DBG_COMMAND_EXCEPTION"));
ExceptionNames.insert(std::make_pair(0x4001000A, "DBG_PRINTEXCEPTION_WIDE_C"));
ExceptionNames.insert(std::make_pair(0x406D1388, "MS_VC_EXCEPTION"));
ExceptionNames.insert(std::make_pair(0x80000001, "EXCEPTION_GUARD_PAGE"));
ExceptionNames.insert(std::make_pair(0x80000002, "EXCEPTION_DATATYPE_MISALIGNMENT"));
ExceptionNames.insert(std::make_pair(0x80000003, "EXCEPTION_BREAKPOINT"));
ExceptionNames.insert(std::make_pair(0x80000004, "EXCEPTION_SINGLE_STEP"));
ExceptionNames.insert(std::make_pair(0x80000026, "STATUS_LONGJUMP"));
ExceptionNames.insert(std::make_pair(0x80000029, "STATUS_UNWIND_CONSOLIDATE"));
ExceptionNames.insert(std::make_pair(0x80010001, "DBG_EXCEPTION_NOT_HANDLED"));
ExceptionNames.insert(std::make_pair(0xC0000005, "EXCEPTION_ACCESS_VIOLATION"));
ExceptionNames.insert(std::make_pair(0xC0000006, "EXCEPTION_IN_PAGE_ERROR"));
ExceptionNames.insert(std::make_pair(0xC0000008, "EXCEPTION_INVALID_HANDLE"));
ExceptionNames.insert(std::make_pair(0xC000000D, "STATUS_INVALID_PARAMETER"));
ExceptionNames.insert(std::make_pair(0xC0000017, "STATUS_NO_MEMORY"));
ExceptionNames.insert(std::make_pair(0xC000001D, "EXCEPTION_ILLEGAL_INSTRUCTION"));
ExceptionNames.insert(std::make_pair(0xC0000025, "EXCEPTION_NONCONTINUABLE_EXCEPTION"));
ExceptionNames.insert(std::make_pair(0xC0000026, "EXCEPTION_INVALID_DISPOSITION"));
ExceptionNames.insert(std::make_pair(0xC000008C, "EXCEPTION_ARRAY_BOUNDS_EXCEEDED"));
ExceptionNames.insert(std::make_pair(0xC000008D, "EXCEPTION_FLT_DENORMAL_OPERAND"));
ExceptionNames.insert(std::make_pair(0xC000008E, "EXCEPTION_FLT_DIVIDE_BY_ZERO"));
ExceptionNames.insert(std::make_pair(0xC000008F, "EXCEPTION_FLT_INEXACT_RESULT"));
ExceptionNames.insert(std::make_pair(0xC0000090, "EXCEPTION_FLT_INVALID_OPERATION"));
ExceptionNames.insert(std::make_pair(0xC0000091, "EXCEPTION_FLT_OVERFLOW"));
ExceptionNames.insert(std::make_pair(0xC0000092, "EXCEPTION_FLT_STACK_CHECK"));
ExceptionNames.insert(std::make_pair(0xC0000093, "EXCEPTION_FLT_UNDERFLOW"));
ExceptionNames.insert(std::make_pair(0xC0000094, "EXCEPTION_INT_DIVIDE_BY_ZERO"));
ExceptionNames.insert(std::make_pair(0xC0000095, "EXCEPTION_INT_OVERFLOW"));
ExceptionNames.insert(std::make_pair(0xC0000096, "EXCEPTION_PRIV_INSTRUCTION"));
ExceptionNames.insert(std::make_pair(0xC00000FD, "EXCEPTION_STACK_OVERFLOW"));
ExceptionNames.insert(std::make_pair(0xC0000135, "STATUS_DLL_NOT_FOUND"));
ExceptionNames.insert(std::make_pair(0xC0000138, "STATUS_ORDINAL_NOT_FOUND"));
ExceptionNames.insert(std::make_pair(0xC0000139, "STATUS_ENTRYPOINT_NOT_FOUND"));
ExceptionNames.insert(std::make_pair(0xC000013A, "STATUS_CONTROL_C_EXIT"));
ExceptionNames.insert(std::make_pair(0xC0000142, "STATUS_DLL_INIT_FAILED"));
ExceptionNames.insert(std::make_pair(0xC000014A, "STATUS_ILLEGAL_FLOAT_CONTEXT"));
ExceptionNames.insert(std::make_pair(0xC0000194, "EXCEPTION_POSSIBLE_DEADLOCK"));
ExceptionNames.insert(std::make_pair(0xC00001A5, "STATUS_INVALID_EXCEPTION_HANDLER"));
ExceptionNames.insert(std::make_pair(0xC00002B4, "STATUS_FLOAT_MULTIPLE_FAULTS"));
ExceptionNames.insert(std::make_pair(0xC00002B5, "STATUS_FLOAT_MULTIPLE_TRAPS"));
ExceptionNames.insert(std::make_pair(0xC00002C5, "STATUS_DATATYPE_MISALIGNMENT_ERROR"));
ExceptionNames.insert(std::make_pair(0xC00002C9, "STATUS_REG_NAT_CONSUMPTION"));
ExceptionNames.insert(std::make_pair(0xC0000374, "STATUS_HEAP_CORRUPTION"));
ExceptionNames.insert(std::make_pair(0xC0000409, "STATUS_STACK_BUFFER_OVERRUN"));
ExceptionNames.insert(std::make_pair(0xC0000417, "STATUS_INVALID_CRUNTIME_PARAMETER"));
ExceptionNames.insert(std::make_pair(0xC000041D, "STATUS_USER_CALLBACK"));
ExceptionNames.insert(std::make_pair(0xC0000420, "STATUS_ASSERTION_FAILURE"));
ExceptionNames.insert(std::make_pair(0xC015000F, "STATUS_SXS_EARLY_DEACTIVATION"));
ExceptionNames.insert(std::make_pair(0xC0150010, "STATUS_SXS_INVALID_DEACTIVATION"));
ExceptionNames.insert(std::make_pair(0xE0434352, "CLR_EXCEPTION"));
ExceptionNames.insert(std::make_pair(0xE06D7363, "CPP_EH_EXCEPTION"));
std::vector<String> lines;
if(!FileHelper::ReadAllLines(exceptionFile, lines))
return false;
auto parseLine = [](const String & line)
{
auto split = StringUtils::Split(line, ' ');
if(int(split.size()) < 2)
{
dprintf("Invalid line: \"%s\"\n", line.c_str());
return false;
}
duint code;
if(!convertNumber(split[0].c_str(), code, 16))
{
dprintf("Failed to convert number \"%s\"\n", split[0].c_str());
return false;
}
ExceptionNames.insert({ code, split[1] });
return true;
};
auto result = true;
for(const auto & line : lines)
if(!parseLine(line))
result = false;
return result;
}
const char* ExceptionCodeToName(unsigned int ExceptionCode)
String ExceptionCodeToName(unsigned int ExceptionCode)
{
if(ExceptionNames.find(ExceptionCode) == ExceptionNames.end())
return nullptr;
return "";
return ExceptionNames[ExceptionCode];
}

View File

@ -3,7 +3,9 @@
#define MS_VC_EXCEPTION 0x406D1388
void ExceptionCodeInit();
const char* ExceptionCodeToName(unsigned int ExceptionCode);
#include "_global.h"
bool ExceptionCodeInit(const String & exceptionFile);
String ExceptionCodeToName(unsigned int ExceptionCode);
#endif // _EXCEPTION_H

View File

@ -41,3 +41,32 @@ bool FileHelper::WriteAllText(const String & fileName, const String & content)
{
return WriteAllData(fileName, content.c_str(), content.length());
}
bool FileHelper::ReadAllLines(const String & fileName, std::vector<String> & lines, bool keepEmpty)
{
String content;
if(!ReadAllText(fileName, content))
return false;
lines.clear();
String line;
for(auto ch : content)
{
switch(ch)
{
case '\r':
break;
case '\n':
if(line.length() || keepEmpty)
lines.push_back(line);
line.clear();
break;
default:
line.resize(line.length() + 1);
line[line.length() - 1] = ch;
break;
}
}
if(line.length())
lines.push_back(line);
return true;
}

View File

@ -10,6 +10,7 @@ public:
static bool WriteAllData(const String & fileName, const void* data, size_t size);
static bool ReadAllText(const String & fileName, String & content);
static bool WriteAllText(const String & fileName, const String & content);
static bool ReadAllLines(const String & fileName, std::vector<String> & lines, bool keepEmpty = false);
};
#endif //_FILEREADER_H

View File

@ -2541,7 +2541,7 @@ CMDRESULT cbHandleClose(int argc, char* argv[])
return STATUS_ERROR;
if(!DuplicateHandle(fdProcessInfo->hProcess, HANDLE(handle), NULL, NULL, 0, FALSE, DUPLICATE_CLOSE_SOURCE))
{
dprintf("DuplicateHandle failed: %s\n", ErrorCodeToName(GetLastError()));
dprintf("DuplicateHandle failed: %s\n", ErrorCodeToName(GetLastError()).c_str());
return STATUS_ERROR;
}
dprintf("Handle %" fext "X closed!\n", handle);

View File

@ -1489,7 +1489,7 @@ static bool ishexnumber(const char* string)
return true;
}
static bool convertNumber(const char* str, duint & result, int radix)
bool convertNumber(const char* str, duint & result, int radix)
{
errno = 0;
char* end;

View File

@ -7,6 +7,7 @@
bool valuesignedcalc();
void valuesetsignedcalc(bool a);
bool valapifromstring(const char* name, duint* value, int* value_size, bool printall, bool silent, bool* hexonly);
bool convertNumber(const char* str, duint & result, int radix);
bool valfromstring_noexpr(const char* string, duint* value, bool silent = true, bool baseonly = false, int* value_size = nullptr, bool* isvar = nullptr, bool* hexonly = nullptr);
bool valfromstring(const char* string, duint* value, bool silent = true, bool baseonly = false, int* value_size = nullptr, bool* isvar = nullptr, bool* hexonly = nullptr);
bool valflagfromstring(duint eflags, const char* string);

View File

@ -23,6 +23,8 @@
#include "database.h"
#include "mnemonichelp.h"
#include "datainst_helper.h"
#include "error.h"
#include "exception.h"
static MESSAGE_STACK* gMsgStack = 0;
static HANDLE hCommandLoopThread = 0;
@ -445,6 +447,18 @@ extern "C" DLL_EXPORT const char* _dbg_dbginit()
else
dputs("Failed to read mnemonic help database...");
// Load error codes
if(ErrorCodeInit(StringUtils::sprintf("%s\\..\\errordb.txt", dir)))
dputs("Error codes database loaded!");
else
dputs("Failed to load error codes...");
// Load exception codes
if(ExceptionCodeInit(StringUtils::sprintf("%s\\..\\exceptiondb.txt", dir)))
dputs("Exception codes database loaded!");
else
dputs("Failed to load exception codes...");
// Create database directory in the local debugger folder
DbSetPath(StringUtils::sprintf("%s\\db", dir).c_str(), nullptr);

View File

@ -1430,7 +1430,7 @@ QString RegistersView::GetRegStringValueFromValue(REGISTER_NAME reg, char* value
else if(reg == LastError)
{
LASTERROR* data = (LASTERROR*)value;
if(data->name)
if(*data->name)
valueText = QString().sprintf("%08X (%s)", data->code, data->name);
else
valueText = QString().sprintf("%08X", data->code);