Implement a proper version of _assert. It nows shows a message box with the details and let's the user choose to either abort, debug or ignore the assertion.
See bug 5486, bug 5507, bug 5511

svn path=/trunk/; revision=48432
This commit is contained in:
Timo Kreuzer 2010-08-03 16:09:33 +00:00
parent 75f1ada3df
commit cf02088179

View file

@ -5,15 +5,68 @@
#include <stdlib.h>
#include <signal.h>
static const char formatstr[] =
"Assertion failed!\n\n"
"Program: %s\n"
"File: %s\n"
"Line: %ld\n\n"
"Expression: %s\n"
"Press Retry to debug the application\n";
/*
* @implemented
*/
void _assert(const char *msg, const char *file, unsigned line)
void _assert(const char *exp, const char *file, unsigned line)
{
/* Assertion failed at foo.c line 45: x<y */
fprintf(stderr, "Assertion failed at %s line %d: %s\n", file, line, msg);
FIXME("Assertion failed at %s line %d: %s\n", file, line, msg);
raise(SIGABRT);
for(;;); /* eliminate warning by mingw */
int (WINAPI *pMessageBoxA)(HWND, LPCTSTR, LPCTSTR, UINT);
HMODULE hmodUser32;
char achProgram[40];
char *pszBuffer;
int len;
int iResult;
/* Assertion failed at foo.c line 45: x<y */
fprintf(stderr, "Assertion failed at %s line %d: %s\n", file, line, exp);
FIXME("Assertion failed at %s line %d: %s\n", file, line, exp);
/* Get MessageBoxA function pointer */
hmodUser32 = LoadLibrary("user32.dll");
pMessageBoxA = GetProcAddress(hmodUser32, "MessageBoxA");
if (!pMessageBoxA)
{
abort();
}
/* Get the file name of the module */
len = GetModuleFileNameA(NULL, achProgram, 40);
/* Calculate full length of the message */
len += sizeof(formatstr) + len + strlen(exp) + strlen(file);
/* Allocate a buffer */
pszBuffer = malloc(len + 1);
/* Format a message */
_snprintf(pszBuffer, len, formatstr, achProgram, file, line, exp);
/* Display a message box */
iResult = pMessageBoxA(NULL,
pszBuffer,
"ReactOS C Runtime Library",
MB_ABORTRETRYIGNORE | MB_ICONERROR);
free(pszBuffer);
/* Does the user want to abort? */
if (iResult == IDABORT)
{
abort();
}
/* Does the user want to debug? */
if (iResult == IDRETRY)
{
__debugbreak();
}
}