ReactOS  0.4.12-dev-918-g6c6e7b8
debug.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING.ARM in the top level directory
3  * PROJECT: ReactOS UEFI Boot Library
4  * FILE: boot/environ/lib/misc/debug.c
5  * PURPOSE: Boot Library Debug Routines
6  * PROGRAMMER: Alex Ionescu (alex.ionescu@reactos.org)
7  */
8 
9 /* INCLUDES ******************************************************************/
10 
11 #include "bl.h"
12 
13 /* DATA VARIABLES ************************************************************/
14 
21 
22 /* FUNCTIONS *****************************************************************/
23 
24 BOOLEAN
26  VOID
27  )
28 {
29  /* Check if BD was initialized, and is currently usable */
31 }
32 
38  )
39 {
40  /* Is the boot debugger enabled? */
41  if (!BlBdDebuggerEnabled())
42  {
43  /* Nothing to pull */
45  }
46 
47  /* TODO */
48  EfiPrintf(L"Todo\r\n");
50 }
51 
52 BOOLEAN
54  VOID
55  )
56 {
58 
59  /* Check if the debugger is initialized */
61 
62  /* Check if it's currently active */
63  Enabled = FALSE;
65  {
66  /* Yep! */
67  Enabled = TRUE;
68  }
69 
70  /* Return enabled state */
71  return Enabled;
72 }
73 
74 VOID
77  ...
78  )
79 {
82  va_list va;
84 
85  va_start(va, Format);
86 
87  /* Check if the boot debugger is enabled */
89 #if (defined(DBG))
90  || TRUE
91 #endif
92  )
93  {
94  /* Print the string out into a buffer */
95  if (vswprintf(BlScratchBuffer, Format, va) > 0)
96  {
97 #if defined(DBG)
99  EfiPrintf(L"\r\n");
100 #endif
101  /* Make it a UNICODE_STRING */
103 
104  /* Then convert it into an ANSI_STRING */
105  AnsiString.Length = 0;
106  AnsiString.MaximumLength = sizeof(AnsiBuffer);
107  AnsiString.Buffer = AnsiBuffer;
109  if (NT_SUCCESS(Status))
110  {
111  /* Print it out to the debugger if that worked */
112  DbgPrint(AnsiString.Buffer);
113  }
114  }
115  }
116 
117  va_end(va);
118 }
119 
120 VOID
123  _In_ ULONG Parameter1,
124  _In_ ULONG_PTR Parameter2,
125  _In_ ULONG_PTR Parameter3,
126  _In_ ULONG_PTR Parameter4
127  )
128 {
130 
131  /* Is this a non-boot error? */
132  if (ErrorCode != 1)
133  {
134  /* Is one already ongoing? */
136  {
137  /* Do we have a custom error handler registered? */
139  {
140  /* Call it, making sure to avoid recursion */
143  Parameter1,
144  Parameter2,
145  Parameter3,
146  Parameter4);
148 
149  /* If the error handler consumed the error, we're done */
150  if (NT_SUCCESS(Status))
151  {
152  return;
153  }
154  }
155  }
156  }
157 
158  /* Check if the boot debugger is enabled */
159  if (BlBdDebuggerEnabled())
160  {
161  /* Print out the fatal error */
162  BlStatusPrint(L"\n"
163  L"*** Fatal Error 0x%08x :\n"
164  L" (0x%p, 0x%p, 0x%p, 0x%p)\n"
165  L"\n",
166  ErrorCode,
167  Parameter1,
168  Parameter2,
169  Parameter3,
170  Parameter4);
171 
172  /* Issue a breakpoint */
173  __debugbreak();
174  }
175 }
176 
ULONG DbgPrint(PCCH Format,...)
Definition: debug.c:420
BOOLEAN BdArchBlockDebuggerOperation
Definition: debug.c:18
CONST WCHAR * PCWCH
Definition: ntbasedef.h:418
#define TRUE
Definition: types.h:120
NTSTATUS BlBdPullRemoteFile(_In_ PWCHAR FilePath, _Out_ PVOID BaseAddress, _Out_ PULONGLONG FileSize)
Definition: debug.c:34
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4418
*BytesInUnicodeString PWCH UnicodeString
Definition: rtlfuncs.h:1980
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
PBL_STATUS_ERROR_HANDLER BlpStatusErrorHandler
Definition: debug.c:20
WCHAR BlScratchBuffer[8192]
Definition: firmware.c:39
char CHAR
Definition: xmlstorage.h:175
LONG NTSTATUS
Definition: precomp.h:26
uint16_t * PWCHAR
Definition: typedefs.h:54
VOID BlStatusPrint(_In_ PCWCH Format,...)
Definition: debug.c:75
void __cdecl __debugbreak(void)
Definition: intrin_ppc.h:698
BOOLEAN BdDebuggerInitialized(VOID)
Definition: debug.c:25
PCWSTR FilePath
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define va_end(ap)
Definition: acmsvcex.h:90
unsigned char BOOLEAN
#define _Out_
Definition: no_sal2.h:323
char * va_list
Definition: acmsvcex.h:78
#define DBG(x)
Definition: moztest.c:12
NTSYSAPI NTSTATUS NTAPI RtlUnicodeStringToAnsiString(PANSI_STRING DestinationString, PUNICODE_STRING SourceString, BOOLEAN AllocateDestinationString)
VOID BlStatusError(_In_ ULONG ErrorCode, _In_ ULONG Parameter1, _In_ ULONG_PTR Parameter2, _In_ ULONG_PTR Parameter3, _In_ ULONG_PTR Parameter4)
Definition: debug.c:121
BOOLEAN BdSubsystemInitialized
Definition: debug.c:17
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
CHAR AnsiBuffer[1024]
Definition: debug.c:15
BOOLEAN BdDebuggerNotPresent
Definition: debug.c:16
static const WCHAR L[]
Definition: oid.c:1250
BOOLEAN BlBdDebuggerEnabled(VOID)
Definition: debug.c:53
#define STATUS_DEBUGGER_INACTIVE
Definition: debugger.c:30
_Must_inspect_result_ _Out_ PLARGE_INTEGER FileSize
Definition: fsrtlfuncs.h:108
BOOLEAN BlpStatusErrorInProgress
Definition: debug.c:19
Status
Definition: gdiplustypes.h:24
#define _In_
Definition: no_sal2.h:204
NTSTATUS(* PBL_STATUS_ERROR_HANDLER)(_In_ ULONG ErrorCode, _In_ ULONG Parameter1, _In_ ULONG_PTR Parameter2, _In_ ULONG_PTR Parameter3, _In_ ULONG_PTR Parameter4)
Definition: bl.h:746
#define va_start(ap, A)
Definition: acmsvcex.h:91
VOID EfiPrintf(_In_ PWCHAR Format,...)
Definition: firmware.c:126
__GNU_EXTENSION typedef unsigned __int64 * PULONGLONG
Definition: ntbasedef.h:390
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
_CRTIMP int __cdecl vswprintf(_Out_ wchar_t *, const wchar_t *, va_list)