ReactOS 0.4.15-dev-8614-gbc76250
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 381 of file debug.c.

383{
384 STRING NameString, CommandString;
385
386 /* Setup the strings */
387 NameString.Buffer = (PCHAR)Name;
388 NameString.Length = (USHORT)strlen(Name);
389 CommandString.Buffer = (PCHAR)Command;
390 CommandString.Length = (USHORT)strlen(Command);
391
392 /* Send them to the debugger */
393 DebugService2(&NameString, &CommandString, BREAKPOINT_COMMAND_STRING);
394}
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 326 of file debug.c.

329{
330 PIMAGE_NT_HEADERS NtHeader;
331 KD_SYMBOLS_INFO SymbolInfo;
332
333 /* Setup the symbol data */
334 SymbolInfo.BaseOfDll = Base;
335 SymbolInfo.ProcessId = ProcessId;
336
337 /* Get NT Headers */
338 NtHeader = RtlImageNtHeader(Base);
339 if (NtHeader)
340 {
341 /* Get the rest of the data */
342 SymbolInfo.CheckSum = NtHeader->OptionalHeader.CheckSum;
343 SymbolInfo.SizeOfImage = NtHeader->OptionalHeader.SizeOfImage;
344 }
345 else
346 {
347 /* No data available */
348 SymbolInfo.CheckSum =
349 SymbolInfo.SizeOfImage = 0;
350 }
351
352 /* Load the symbols */
354}
#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:2451
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 206 of file debug.c.

208{
210 va_list ap;
211
212 /* Call the internal routine that also handles ControlC */
215 -1,
217 Format,
218 ap,
219 TRUE);
220 va_end(ap);
221 return Status;
222}
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 229 of file debug.c.

233{
235 va_list ap;
236
237 /* Call the internal routine that also handles ControlC */
241 Level,
242 Format,
243 ap,
244 TRUE);
245 va_end(ap);
246 return Status;
247}
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 254 of file debug.c.

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

◆ DbgPrompt()

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

Definition at line 277 of file debug.c.

280{
283
284 /* Setup the input string */
285 Input.MaximumLength = (USHORT)MaximumResponseLength;
286 Input.Buffer = Response;
287
288 /* Setup the output string */
289 Output.Length = (USHORT)strlen(Prompt);
290 Output.Buffer = (PCHAR)Prompt;
291
292 /* Call the system service */
293 return DebugPrompt(&Output, &Input);
294}
@ 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 301 of file debug.c.

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

◆ DbgSetDebugFilterState()

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

Definition at line 313 of file debug.c.

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

◆ DbgUnLoadImageSymbols()

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

Definition at line 361 of file debug.c.

364{
365 KD_SYMBOLS_INFO SymbolInfo;
366
367 /* Setup the symbol data */
368 SymbolInfo.BaseOfDll = Base;
369 SymbolInfo.ProcessId = ProcessId;
370 SymbolInfo.CheckSum = SymbolInfo.SizeOfImage = 0;
371
372 /* Load the symbols */
374}
#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}
static CCHAR DebugString[256]
Definition: settings.c:16
#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 421 of file debug.c.

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

◆ RtlPopFrame()

VOID NTAPI RtlPopFrame ( IN PTEB_ACTIVE_FRAME  Frame)

Definition at line 401 of file debug.c.

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

◆ RtlPushFrame()

VOID NTAPI RtlPushFrame ( IN PTEB_ACTIVE_FRAME  Frame)

Definition at line 412 of file debug.c.

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

◆ vDbgPrintEx()

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

Definition at line 187 of file debug.c.

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

◆ vDbgPrintExWithPrefix()

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

Definition at line 167 of file debug.c.

172{
173 /* Call the internal routine that also handles ControlC */
176 Level,
177 Format,
178 ap,
179 TRUE);
180}
_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) - 2] = '\n';
106 Buffer[sizeof(Buffer) - 1] = '\0';
107
108 /* Put maximum */
109 Length = sizeof(Buffer) - 1;
110 }
111 else
112 {
113 /* Add the prefix */
114 Length += PrefixLength;
115 }
116
117 /* Build the string */
118 DebugString.Length = (USHORT)Length;
119 DebugString.Buffer = Buffer;
120
121 /* First, let the debugger know as well */
123 {
124 /* Fill out an exception record */
125 ExceptionRecord.ExceptionCode = DBG_PRINTEXCEPTION_C;
126 ExceptionRecord.ExceptionRecord = NULL;
127 ExceptionRecord.NumberParameters = 2;
128 ExceptionRecord.ExceptionFlags = 0;
129 ExceptionRecord.ExceptionInformation[0] = DebugString.Length + 1;
130 ExceptionRecord.ExceptionInformation[1] = (ULONG_PTR)DebugString.Buffer;
131
132 /* Raise the exception */
133 RtlRaiseException(&ExceptionRecord);
134
135 /* In user-mode, clear the InDbgPrint Flag */
137 return STATUS_SUCCESS;
138 }
139
140 /* Call the Debug Print routine */
142
143 /* Check if this was with Control-C */
144 if (HandleBreakpoint)
145 {
146 /* Check if we got a breakpoint */
148 {
149 /* Breakpoint */
152 }
153 }
154
155 /* In user-mode, clear the InDbgPrint Flag */
157
158 /* Return */
159 return Status;
160}
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:27
VOID NTAPI RtlpClearInDbgPrint(VOID)
Definition: libsupp.c:47
BOOLEAN NTAPI RtlpSetInDbgPrint(VOID)
Definition: libsupp.c:35
#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:165
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:66
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168
#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().