mirror of
https://github.com/reactos/reactos.git
synced 2025-08-04 00:05:44 +00:00
[CRT]
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:
parent
75f1ada3df
commit
cf02088179
1 changed files with 59 additions and 6 deletions
|
@ -5,15 +5,68 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <signal.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
|
* @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 */
|
int (WINAPI *pMessageBoxA)(HWND, LPCTSTR, LPCTSTR, UINT);
|
||||||
fprintf(stderr, "Assertion failed at %s line %d: %s\n", file, line, msg);
|
HMODULE hmodUser32;
|
||||||
FIXME("Assertion failed at %s line %d: %s\n", file, line, msg);
|
char achProgram[40];
|
||||||
raise(SIGABRT);
|
char *pszBuffer;
|
||||||
for(;;); /* eliminate warning by mingw */
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue