ReactOS 0.4.15-dev-7834-g00c4b3d
debug.c File Reference
#include <rtl.h>
#include <ndk/kdfuncs.h>
#include <debug.h>
Include dependency graph for debug.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

ULONG NTAPI DebugPrint (IN PSTRING DebugString, IN ULONG ComponentId, IN ULONG Level)
 
ULONG NTAPI DebugPrompt (IN PSTRING Output, IN PSTRING Input)
 
ULONG NTAPI vDbgPrintExWithPrefixInternal (IN PCCH Prefix, IN ULONG ComponentId, IN ULONG Level, IN PCCH Format, IN va_list ap, IN BOOLEAN HandleBreakpoint)
 
ULONG NTAPI vDbgPrintExWithPrefix (IN PCCH Prefix, IN ULONG ComponentId, IN ULONG Level, IN PCCH Format, IN va_list ap)
 
ULONG NTAPI vDbgPrintEx (IN ULONG ComponentId, IN ULONG Level, IN PCCH Format, IN va_list ap)
 
ULONG __cdecl DbgPrint (PCCH Format,...)
 
ULONG __cdecl DbgPrintEx (IN ULONG ComponentId, IN ULONG Level, IN PCCH Format,...)
 
ULONG __cdecl DbgPrintReturnControlC (PCCH Format,...)
 
ULONG NTAPI DbgPrompt (IN PCCH Prompt, OUT PCH Response, IN ULONG MaximumResponseLength)
 
NTSTATUS NTAPI DbgQueryDebugFilterState (IN ULONG ComponentId, IN ULONG Level)
 
NTSTATUS NTAPI DbgSetDebugFilterState (IN ULONG ComponentId, IN ULONG Level, IN BOOLEAN State)
 
VOID NTAPI DbgLoadImageSymbols (IN PSTRING Name, IN PVOID Base, IN ULONG_PTR ProcessId)
 
VOID NTAPI DbgUnLoadImageSymbols (IN PSTRING Name, IN PVOID Base, IN ULONG_PTR ProcessId)
 
VOID NTAPI DbgCommandString (IN PCCH Name, IN PCCH Command)
 
VOID NTAPI RtlPopFrame (IN PTEB_ACTIVE_FRAME Frame)
 
VOID NTAPI RtlPushFrame (IN PTEB_ACTIVE_FRAME Frame)
 
PTEB_ACTIVE_FRAME NTAPI RtlGetFrame (VOID)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 16 of file debug.c.

Function Documentation

◆ DbgCommandString()

VOID NTAPI DbgCommandString ( IN PCCH  Name,
IN PCCH  Command 
)

Definition at line 380 of file debug.c.

382{
383 STRING NameString, CommandString;
384
385 /* Setup the strings */
386 NameString.Buffer = (PCHAR)Name;
387 NameString.Length = (USHORT)strlen(Name);
388 CommandString.Buffer = (PCHAR)Command;
389 CommandString.Length = (USHORT)strlen(Command);
390
391 /* Send them to the debugger */
392 DebugService2(&NameString, &CommandString, BREAKPOINT_COMMAND_STRING);
393}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
std::wstring STRING
Definition: fontsub.cpp:33
#define PCHAR
Definition: match.c:90
#define BREAKPOINT_COMMAND_STRING
Definition: kdtypes.h:55
unsigned short USHORT
Definition: pedump.c:61
VOID NTAPI DebugService2(IN PVOID Argument1, IN PVOID Argument2, IN ULONG Service)
Definition: shell.h:41

◆ DbgLoadImageSymbols()

VOID NTAPI DbgLoadImageSymbols ( IN PSTRING  Name,
IN PVOID  Base,
IN ULONG_PTR  ProcessId 
)

Definition at line 325 of file debug.c.

328{
329 PIMAGE_NT_HEADERS NtHeader;
330 KD_SYMBOLS_INFO SymbolInfo;
331
332 /* Setup the symbol data */
333 SymbolInfo.BaseOfDll = Base;
334 SymbolInfo.ProcessId = ProcessId;
335
336 /* Get NT Headers */
337 NtHeader = RtlImageNtHeader(Base);
338 if (NtHeader)
339 {
340 /* Get the rest of the data */
341 SymbolInfo.CheckSum = NtHeader->OptionalHeader.CheckSum;
342 SymbolInfo.SizeOfImage = NtHeader->OptionalHeader.SizeOfImage;
343 }
344 else
345 {
346 /* No data available */
347 SymbolInfo.CheckSum =
348 SymbolInfo.SizeOfImage = 0;
349 }
350
351 /* Load the symbols */
353}
#define RtlImageNtHeader
Definition: compat.h:806
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ProcessId
Definition: fatprocs.h:2711
#define BREAKPOINT_LOAD_SYMBOLS
Definition: kdtypes.h:53
_In_opt_ ULONG Base
Definition: rtlfuncs.h:2439
IMAGE_OPTIONAL_HEADER32 OptionalHeader
Definition: ntddk_ex.h:184
ULONG_PTR ProcessId
Definition: kdtypes.h:171
ULONG SizeOfImage
Definition: kdtypes.h:173
ULONG CheckSum
Definition: kdtypes.h:172
PVOID BaseOfDll
Definition: kdtypes.h:170

◆ DbgPrint()

ULONG __cdecl DbgPrint ( PCCH  Format,
  ... 
)

Definition at line 205 of file debug.c.

207{
209 va_list ap;
210
211 /* Call the internal routine that also handles ControlC */
214 -1,
216 Format,
217 ap,
218 TRUE);
219 va_end(ap);
220 return Status;
221}
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define DPFLTR_ERROR_LEVEL
Definition: main.cpp:32
#define TRUE
Definition: types.h:120
Status
Definition: gdiplustypes.h:25
ULONG NTAPI vDbgPrintExWithPrefixInternal(IN PCCH Prefix, IN ULONG ComponentId, IN ULONG Level, IN PCCH Format, IN va_list ap, IN BOOLEAN HandleBreakpoint)
Definition: debug.c:52
uint32_t ULONG
Definition: typedefs.h:59
void int int ULONGLONG int va_list * ap
Definition: winesup.h:36

◆ DbgPrintEx()

ULONG __cdecl DbgPrintEx ( IN ULONG  ComponentId,
IN ULONG  Level,
IN PCCH  Format,
  ... 
)

Definition at line 228 of file debug.c.

232{
234 va_list ap;
235
236 /* Call the internal routine that also handles ControlC */
240 Level,
241 Format,
242 ap,
243 TRUE);
244 va_end(ap);
245 return Status;
246}
ACPI_BUFFER *RetBuffer ACPI_BUFFER *RetBuffer char ACPI_WALK_RESOURCE_CALLBACK void *Context ACPI_BUFFER *RetBuffer UINT16 ACPI_RESOURCE **ResourcePtr ACPI_GENERIC_ADDRESS *Reg UINT32 *ReturnValue UINT8 UINT8 *Slp_TypB ACPI_PHYSICAL_ADDRESS PhysicalAddress64 UINT32 UINT32 *TimeElapsed UINT32 ACPI_STATUS const char UINT32 ACPI_STATUS const char UINT32 const char const char UINT32 ComponentId
Definition: acpixf.h:1281
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:56

◆ DbgPrintReturnControlC()

ULONG __cdecl DbgPrintReturnControlC ( PCCH  Format,
  ... 
)

Definition at line 253 of file debug.c.

255{
257 va_list ap;
258
259 /* Call the internal routine that also handles ControlC */
262 -1,
264 Format,
265 ap,
266 FALSE);
267 va_end(ap);
268 return Status;
269}
#define FALSE
Definition: types.h:117

◆ DbgPrompt()

ULONG NTAPI DbgPrompt ( IN PCCH  Prompt,
OUT PCH  Response,
IN ULONG  MaximumResponseLength 
)

Definition at line 276 of file debug.c.

279{
282
283 /* Setup the input string */
284 Input.MaximumLength = (USHORT)MaximumResponseLength;
285 Input.Buffer = Response;
286
287 /* Setup the output string */
288 Output.Length = (USHORT)strlen(Prompt);
289 Output.Buffer = (PCHAR)Prompt;
290
291 /* Call the system service */
292 return DebugPrompt(&Output, &Input);
293}
@ Input
Definition: arc.h:84
@ Output
Definition: arc.h:85
ULONG NTAPI DebugPrompt(IN PSTRING Output, IN PSTRING Input)
Definition: debug.c:37
Definition: ncftp.h:89
_In_ ULONG MaximumResponseLength
Definition: kdfuncs.h:11

◆ DbgQueryDebugFilterState()

NTSTATUS NTAPI DbgQueryDebugFilterState ( IN ULONG  ComponentId,
IN ULONG  Level 
)

Definition at line 300 of file debug.c.

302{
303 /* Call the Nt routine */
305}
NTSTATUS NTAPI NtQueryDebugFilterState(_In_ ULONG ComponentId, _In_ ULONG Level)
Definition: kdapi.c:2357

◆ DbgSetDebugFilterState()

NTSTATUS NTAPI DbgSetDebugFilterState ( IN ULONG  ComponentId,
IN ULONG  Level,
IN BOOLEAN  State 
)

Definition at line 312 of file debug.c.

315{
316 /* Call the Nt routine */
318}
NTSTATUS NTAPI NtSetDebugFilterState(_In_ ULONG ComponentId, _In_ ULONG Level, _In_ BOOLEAN State)
Definition: kdapi.c:2411

◆ DbgUnLoadImageSymbols()

VOID NTAPI DbgUnLoadImageSymbols ( IN PSTRING  Name,
IN PVOID  Base,
IN ULONG_PTR  ProcessId 
)

Definition at line 360 of file debug.c.

363{
364 KD_SYMBOLS_INFO SymbolInfo;
365
366 /* Setup the symbol data */
367 SymbolInfo.BaseOfDll = Base;
368 SymbolInfo.ProcessId = ProcessId;
369 SymbolInfo.CheckSum = SymbolInfo.SizeOfImage = 0;
370
371 /* Load the symbols */
373}
#define BREAKPOINT_UNLOAD_SYMBOLS
Definition: kdtypes.h:54

◆ DebugPrint()

ULONG NTAPI DebugPrint ( IN PSTRING  DebugString,
IN ULONG  ComponentId,
IN ULONG  Level 
)

Definition at line 23 of file debug.c.

26{
27 /* Call the Debug Service */
29 DebugString->Buffer,
30 UlongToPtr(DebugString->Length),
33}
CCHAR DebugString[256]
Definition: cmdline.c:22
#define UlongToPtr(u)
Definition: config.h:106
#define BREAKPOINT_PRINT
Definition: kdtypes.h:51
ULONG NTAPI DebugService(IN ULONG Service, IN PVOID Argument1, IN PVOID Argument2, IN PVOID Argument3, IN PVOID Argument4)

◆ DebugPrompt()

ULONG NTAPI DebugPrompt ( IN PSTRING  Output,
IN PSTRING  Input 
)

Definition at line 37 of file debug.c.

39{
40 /* Call the Debug Service */
42 Output->Buffer,
43 UlongToPtr(Output->Length),
44 Input->Buffer,
45 UlongToPtr(Input->MaximumLength));
46}
#define BREAKPOINT_PROMPT
Definition: kdtypes.h:52

Referenced by DbgPrompt().

◆ RtlGetFrame()

PTEB_ACTIVE_FRAME NTAPI RtlGetFrame ( VOID  )

Definition at line 420 of file debug.c.

421{
422 /* Return the frame that's currently active */
423 return NtCurrentTeb()->ActiveFrame;
424}
#define NtCurrentTeb

◆ RtlPopFrame()

VOID NTAPI RtlPopFrame ( IN PTEB_ACTIVE_FRAME  Frame)

Definition at line 400 of file debug.c.

401{
402 /* Restore the previous frame as the active one */
403 NtCurrentTeb()->ActiveFrame = Frame->Previous;
404}

◆ RtlPushFrame()

VOID NTAPI RtlPushFrame ( IN PTEB_ACTIVE_FRAME  Frame)

Definition at line 411 of file debug.c.

412{
413 /* Save the current frame and set the new one as active */
414 Frame->Previous = NtCurrentTeb()->ActiveFrame;
415 NtCurrentTeb()->ActiveFrame = Frame;
416}

◆ vDbgPrintEx()

ULONG NTAPI vDbgPrintEx ( IN ULONG  ComponentId,
IN ULONG  Level,
IN PCCH  Format,
IN va_list  ap 
)

Definition at line 186 of file debug.c.

190{
191 /* Call the internal routine that also handles ControlC */
194 Level,
195 Format,
196 ap,
197 TRUE);
198}

◆ vDbgPrintExWithPrefix()

ULONG NTAPI vDbgPrintExWithPrefix ( IN PCCH  Prefix,
IN ULONG  ComponentId,
IN ULONG  Level,
IN PCCH  Format,
IN va_list  ap 
)

Definition at line 166 of file debug.c.

171{
172 /* Call the internal routine that also handles ControlC */
175 Level,
176 Format,
177 ap,
178 TRUE);
179}
_In_ __drv_aliasesMem PSTRING Prefix
Definition: rtlfuncs.h:1630

◆ vDbgPrintExWithPrefixInternal()

ULONG NTAPI vDbgPrintExWithPrefixInternal ( IN PCCH  Prefix,
IN ULONG  ComponentId,
IN ULONG  Level,
IN PCCH  Format,
IN va_list  ap,
IN BOOLEAN  HandleBreakpoint 
)

Definition at line 52 of file debug.c.

58{
61 CHAR Buffer[512];
62 SIZE_T Length, PrefixLength;
63 EXCEPTION_RECORD ExceptionRecord;
64
65 /* Check if we should print it or not */
66 if ((ComponentId != MAXULONG) &&
68 {
69 /* This message is masked */
70 return STATUS_SUCCESS;
71 }
72
73 /* For user mode, don't recursively DbgPrint */
75
76 /* Guard against incorrect pointers */
78 {
79 /* Get the length and normalize it */
80 PrefixLength = strlen(Prefix);
81 if (PrefixLength > sizeof(Buffer)) PrefixLength = sizeof(Buffer);
82
83 /* Copy it */
84 strncpy(Buffer, Prefix, PrefixLength);
85
86 /* Do the printf */
87 Length = _vsnprintf(Buffer + PrefixLength,
88 sizeof(Buffer) - PrefixLength,
89 Format,
90 ap);
91 }
93 {
94 /* In user-mode, clear the InDbgPrint Flag */
96 /* Fail */
98 }
100
101 /* Check if we went past the buffer */
102 if (Length == MAXULONG)
103 {
104 /* Terminate it if we went over-board */
105 Buffer[sizeof(Buffer) - 1] = '\n';
106
107 /* Put maximum */
108 Length = sizeof(Buffer);
109 }
110 else
111 {
112 /* Add the prefix */
113 Length += PrefixLength;
114 }
115
116 /* Build the string */
117 DebugString.Length = (USHORT)Length;
118 DebugString.Buffer = Buffer;
119
120 /* First, let the debugger know as well */
122 {
123 /* Fill out an exception record */
124 ExceptionRecord.ExceptionCode = DBG_PRINTEXCEPTION_C;
125 ExceptionRecord.ExceptionRecord = NULL;
126 ExceptionRecord.NumberParameters = 2;
127 ExceptionRecord.ExceptionFlags = 0;
128 ExceptionRecord.ExceptionInformation[0] = DebugString.Length + 1;
129 ExceptionRecord.ExceptionInformation[1] = (ULONG_PTR)DebugString.Buffer;
130
131 /* Raise the exception */
132 RtlRaiseException(&ExceptionRecord);
133
134 /* In user-mode, clear the InDbgPrint Flag */
136 return STATUS_SUCCESS;
137 }
138
139 /* Call the Debug Print routine */
141
142 /* Check if this was with Control-C */
143 if (HandleBreakpoint)
144 {
145 /* Check if we got a breakpoint */
147 {
148 /* Breakpoint */
151 }
152 }
153
154 /* In user-mode, clear the InDbgPrint Flag */
156
157 /* Return */
158 return Status;
159}
char * strncpy(char *DstString, const char *SrcString, ACPI_SIZE Count)
Definition: utclib.c:427
LONG NTSTATUS
Definition: precomp.h:26
Definition: bufpool.h:45
#define DebugPrint(x)
Definition: classpnp.h:125
#define NULL
Definition: types.h:112
BOOLEAN NTAPI RtlpCheckForActiveDebugger(VOID)
Definition: libsupp.c:25
VOID NTAPI RtlpClearInDbgPrint(VOID)
Definition: libsupp.c:45
BOOLEAN NTAPI RtlpSetInDbgPrint(VOID)
Definition: libsupp.c:33
#define ULONG_PTR
Definition: config.h:101
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define DBG_STATUS_CONTROL_C
Definition: kdtypes.h:39
NTSYSAPI VOID NTAPI RtlRaiseException(_In_ PEXCEPTION_RECORD ExceptionRecord)
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define STATUS_BREAKPOINT
Definition: ntstatus.h:184
#define DBG_PRINTEXCEPTION_C
Definition: ntstatus.h:53
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:159
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:34
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:162
#define STATUS_SUCCESS
Definition: shellext.h:65
struct _EXCEPTION_RECORD * ExceptionRecord
Definition: compat.h:210
DWORD ExceptionCode
Definition: compat.h:208
DWORD NumberParameters
Definition: compat.h:212
DWORD ExceptionFlags
Definition: compat.h:209
ULONG_PTR ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS]
Definition: compat.h:213
#define MAXULONG
Definition: typedefs.h:251
ULONG_PTR SIZE_T
Definition: typedefs.h:80
__analysis_noreturn NTSYSAPI VOID NTAPI DbgBreakPointWithStatus(_In_ ULONG Status)
#define _vsnprintf
Definition: xmlstorage.h:202
char CHAR
Definition: xmlstorage.h:175

Referenced by DbgPrint(), DbgPrintEx(), DbgPrintReturnControlC(), vDbgPrintEx(), and vDbgPrintExWithPrefix().