[RTL/NTDLL]
[reactos.git] / reactos / lib / rtl / assert.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Run-Time Library
4 * PURPOSE: Implements RtlAssert used by the ASSERT
5 * and ASSERTMSG debugging macros
6 * FILE: lib/rtl/assert.c
7 * PROGRAMERS: Stefan Ginsberg (stefan.ginsberg@reactos.org)
8 */
9
10 /* INCLUDES *****************************************************************/
11
12 #include <rtl.h>
13 #define NDEBUG
14 #include <debug.h>
15
16 /* PUBLIC FUNCTIONS **********************************************************/
17
18 /*
19 * @implemented
20 */
21 VOID
22 NTAPI
23 RtlAssert(IN PVOID FailedAssertion,
24 IN PVOID FileName,
25 IN ULONG LineNumber,
26 IN PCHAR Message OPTIONAL)
27 {
28 #if 0 // Disabled until sysreg can handle debug prompts
29 CHAR Action[2];
30 CONTEXT Context;
31
32 /* Capture caller's context for the debugger */
33 RtlCaptureContext(&Context);
34
35 /* Enter prompt loop */
36 for (;;)
37 {
38 /* Print the assertion */
39 DbgPrint("\n*** Assertion failed: %s%s\n"
40 "*** Source File: %s, line %ld\n\n",
41 Message != NULL ? Message : "",
42 (PSTR)FailedAssertion,
43 (PSTR)FileName,
44 LineNumber);
45
46 /* Prompt for action */
47 DbgPrompt("Break repeatedly, break Once, Ignore,"
48 " terminate Process or terminate Thread (boipt)? ",
49 Action,
50 sizeof(Action));
51 switch (Action[0])
52 {
53 /* Break repeatedly */
54 case 'B': case 'b':
55
56 /* Do a breakpoint, then prompt again */
57 DbgPrint("Execute '.cxr %p' to dump context\n", &Context);
58 DbgBreakPoint();
59 break;
60
61 /* Ignore */
62 case 'I': case 'i':
63
64 /* Return to caller */
65 return;
66
67 /* Break once */
68 case 'O': case 'o':
69
70 /* Do a breakpoint and return */
71 DbgPrint("Execute '.cxr %p' to dump context\n", &Context);
72 DbgBreakPoint();
73 return;
74
75 /* Terminate process*/
76 case 'P': case 'p':
77
78 /* Terminate us */
79 ZwTerminateProcess(ZwCurrentProcess(), STATUS_UNSUCCESSFUL);
80 break;
81
82 /* Terminate thread */
83 case 'T': case 't':
84
85 /* Terminate us */
86 ZwTerminateThread(ZwCurrentThread(), STATUS_UNSUCCESSFUL);
87 break;
88
89 /* Unrecognized */
90 default:
91
92 /* Prompt again */
93 break;
94 }
95 }
96
97 /* Shouldn't get here */
98 DbgBreakPoint();
99 ZwTerminateProcess(ZwCurrentProcess(), STATUS_UNSUCCESSFUL);
100 #else
101 if (NULL != Message)
102 {
103 DbgPrint("Assertion \'%s\' failed at %s line %u: %s\n",
104 (PCHAR)FailedAssertion,
105 (PCHAR)FileName,
106 LineNumber,
107 Message);
108 }
109 else
110 {
111 DbgPrint("Assertion \'%s\' failed at %s line %u\n",
112 (PCHAR)FailedAssertion,
113 (PCHAR)FileName,
114 LineNumber);
115 }
116
117 DbgBreakPoint();
118 #endif
119 }