2006-11-08 11:47:44 +00:00
|
|
|
/*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS Run-Time Library
|
2009-01-18 15:59:21 +00:00
|
|
|
* FILE: lib/rtl/debug.c
|
2006-11-08 11:47:44 +00:00
|
|
|
* PURPOSE: Debug Print and Prompt routines
|
|
|
|
* PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
|
|
|
|
* Royce Mitchel III
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *****************************************************************/
|
|
|
|
|
|
|
|
#include <rtl.h>
|
|
|
|
|
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
/* PRIVATE FUNCTIONS ********************************************************/
|
|
|
|
|
2009-10-25 15:56:38 +00:00
|
|
|
ULONG
|
2006-11-08 11:47:44 +00:00
|
|
|
NTAPI
|
2009-10-25 15:56:38 +00:00
|
|
|
DebugPrint(IN PSTRING DebugString,
|
2006-11-08 11:47:44 +00:00
|
|
|
IN ULONG ComponentId,
|
|
|
|
IN ULONG Level)
|
|
|
|
{
|
2009-10-23 22:51:39 +00:00
|
|
|
/* Call the Debug Service */
|
2006-11-08 11:47:44 +00:00
|
|
|
return DebugService(BREAKPOINT_PRINT,
|
|
|
|
DebugString->Buffer,
|
2009-10-25 15:56:38 +00:00
|
|
|
UlongToPtr(DebugString->Length),
|
2006-11-08 11:47:44 +00:00
|
|
|
UlongToPtr(ComponentId),
|
2007-03-02 06:11:27 +00:00
|
|
|
UlongToPtr(Level));
|
2006-11-08 11:47:44 +00:00
|
|
|
}
|
|
|
|
|
2009-10-25 15:56:38 +00:00
|
|
|
ULONG
|
2006-11-08 11:47:44 +00:00
|
|
|
NTAPI
|
2009-10-25 15:56:38 +00:00
|
|
|
DebugPrompt(IN PSTRING Output,
|
2006-11-19 21:14:49 +00:00
|
|
|
IN PSTRING Input)
|
2006-11-08 11:47:44 +00:00
|
|
|
{
|
2009-10-23 22:51:39 +00:00
|
|
|
/* Call the Debug Service */
|
2006-11-08 11:47:44 +00:00
|
|
|
return DebugService(BREAKPOINT_PROMPT,
|
|
|
|
Output->Buffer,
|
2009-10-25 15:56:38 +00:00
|
|
|
UlongToPtr(Output->Length),
|
2006-11-08 11:47:44 +00:00
|
|
|
Input->Buffer,
|
|
|
|
UlongToPtr(Input->MaximumLength));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FUNCTIONS ****************************************************************/
|
|
|
|
|
|
|
|
ULONG
|
|
|
|
NTAPI
|
2009-10-25 15:56:38 +00:00
|
|
|
vDbgPrintExWithPrefixInternal(IN PCCH Prefix,
|
2006-11-08 11:47:44 +00:00
|
|
|
IN ULONG ComponentId,
|
|
|
|
IN ULONG Level,
|
2009-10-25 15:56:38 +00:00
|
|
|
IN PCCH Format,
|
2006-11-08 11:47:44 +00:00
|
|
|
IN va_list ap,
|
|
|
|
IN BOOLEAN HandleBreakpoint)
|
|
|
|
{
|
2009-08-24 19:58:15 +00:00
|
|
|
NTSTATUS Status;
|
2009-10-25 15:56:38 +00:00
|
|
|
STRING DebugString;
|
2006-11-08 11:47:44 +00:00
|
|
|
CHAR Buffer[512];
|
2011-09-20 17:33:51 +00:00
|
|
|
SIZE_T Length, PrefixLength;
|
2006-11-08 11:47:44 +00:00
|
|
|
EXCEPTION_RECORD ExceptionRecord;
|
|
|
|
|
|
|
|
/* Check if we should print it or not */
|
2009-09-27 20:07:43 +00:00
|
|
|
if ((ComponentId != MAXULONG) &&
|
2009-10-25 15:56:38 +00:00
|
|
|
(NtQueryDebugFilterState(ComponentId, Level)) != TRUE)
|
2006-11-08 11:47:44 +00:00
|
|
|
{
|
|
|
|
/* This message is masked */
|
2009-08-24 19:58:15 +00:00
|
|
|
return STATUS_SUCCESS;
|
2006-11-08 11:47:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* For user mode, don't recursively DbgPrint */
|
2009-11-02 17:45:51 +00:00
|
|
|
if (RtlpSetInDbgPrint()) return STATUS_SUCCESS;
|
2006-11-08 11:47:44 +00:00
|
|
|
|
2008-08-21 22:41:17 +00:00
|
|
|
/* Guard against incorrect pointers */
|
2008-11-30 19:28:11 +00:00
|
|
|
_SEH2_TRY
|
2006-11-08 11:47:44 +00:00
|
|
|
{
|
2008-08-21 22:41:17 +00:00
|
|
|
/* Get the length and normalize it */
|
|
|
|
PrefixLength = strlen(Prefix);
|
|
|
|
if (PrefixLength > sizeof(Buffer)) PrefixLength = sizeof(Buffer);
|
2006-11-08 11:47:44 +00:00
|
|
|
|
|
|
|
/* Copy it */
|
2008-08-21 22:41:17 +00:00
|
|
|
strncpy(Buffer, Prefix, PrefixLength);
|
2008-10-29 20:06:44 +00:00
|
|
|
|
2008-08-21 22:41:17 +00:00
|
|
|
/* Do the printf */
|
|
|
|
Length = _vsnprintf(Buffer + PrefixLength,
|
|
|
|
sizeof(Buffer) - PrefixLength,
|
|
|
|
Format,
|
|
|
|
ap);
|
2006-11-08 11:47:44 +00:00
|
|
|
}
|
2008-11-30 19:28:11 +00:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2008-08-21 22:41:17 +00:00
|
|
|
{
|
|
|
|
/* Fail */
|
2009-08-24 19:58:15 +00:00
|
|
|
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
2008-08-21 22:41:17 +00:00
|
|
|
}
|
2008-11-30 19:28:11 +00:00
|
|
|
_SEH2_END;
|
2006-11-08 11:47:44 +00:00
|
|
|
|
|
|
|
/* Check if we went past the buffer */
|
2009-09-27 20:07:43 +00:00
|
|
|
if (Length == MAXULONG)
|
2006-11-08 11:47:44 +00:00
|
|
|
{
|
|
|
|
/* Terminate it if we went over-board */
|
|
|
|
Buffer[sizeof(Buffer) - 1] = '\n';
|
|
|
|
|
|
|
|
/* Put maximum */
|
|
|
|
Length = sizeof(Buffer);
|
|
|
|
}
|
2008-08-21 22:41:17 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Add the prefix */
|
|
|
|
Length += PrefixLength;
|
|
|
|
}
|
2008-10-29 20:06:44 +00:00
|
|
|
|
2008-08-21 22:41:17 +00:00
|
|
|
/* Build the string */
|
2011-09-20 17:33:51 +00:00
|
|
|
DebugString.Length = (USHORT)Length;
|
2008-08-21 22:41:17 +00:00
|
|
|
DebugString.Buffer = Buffer;
|
2006-11-08 11:47:44 +00:00
|
|
|
|
|
|
|
/* First, let the debugger know as well */
|
2009-10-23 22:51:39 +00:00
|
|
|
if (RtlpCheckForActiveDebugger())
|
2006-11-08 11:47:44 +00:00
|
|
|
{
|
|
|
|
/* Fill out an exception record */
|
|
|
|
ExceptionRecord.ExceptionCode = DBG_PRINTEXCEPTION_C;
|
|
|
|
ExceptionRecord.ExceptionRecord = NULL;
|
|
|
|
ExceptionRecord.NumberParameters = 2;
|
|
|
|
ExceptionRecord.ExceptionFlags = 0;
|
|
|
|
ExceptionRecord.ExceptionInformation[0] = DebugString.Length + 1;
|
|
|
|
ExceptionRecord.ExceptionInformation[1] = (ULONG_PTR)DebugString.Buffer;
|
|
|
|
|
|
|
|
/* Raise the exception */
|
|
|
|
RtlRaiseException(&ExceptionRecord);
|
|
|
|
|
|
|
|
/* This code only runs in user-mode, so setting the flag is safe */
|
|
|
|
NtCurrentTeb()->InDbgPrint = FALSE;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Call the Debug Print routine */
|
|
|
|
Status = DebugPrint(&DebugString, ComponentId, Level);
|
|
|
|
|
|
|
|
/* Check if this was with Control-C */
|
|
|
|
if (HandleBreakpoint)
|
|
|
|
{
|
|
|
|
/* Check if we got a breakpoint */
|
|
|
|
if (Status == STATUS_BREAKPOINT)
|
|
|
|
{
|
|
|
|
/* Breakpoint */
|
2009-11-02 17:45:51 +00:00
|
|
|
DbgBreakPointWithStatus(DBG_STATUS_CONTROL_C);
|
2006-11-08 11:47:44 +00:00
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-02 17:45:51 +00:00
|
|
|
/* In user-mode, clear the InDbgPrint Flag */
|
|
|
|
RtlpClearInDbgPrint();
|
2006-11-08 11:47:44 +00:00
|
|
|
|
|
|
|
/* Return */
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
ULONG
|
|
|
|
NTAPI
|
2009-10-25 15:56:38 +00:00
|
|
|
vDbgPrintExWithPrefix(IN PCCH Prefix,
|
2006-11-08 11:47:44 +00:00
|
|
|
IN ULONG ComponentId,
|
|
|
|
IN ULONG Level,
|
2009-10-25 15:56:38 +00:00
|
|
|
IN PCCH Format,
|
2006-11-08 11:47:44 +00:00
|
|
|
IN va_list ap)
|
|
|
|
{
|
|
|
|
/* Call the internal routine that also handles ControlC */
|
|
|
|
return vDbgPrintExWithPrefixInternal(Prefix,
|
|
|
|
ComponentId,
|
|
|
|
Level,
|
|
|
|
Format,
|
|
|
|
ap,
|
|
|
|
TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
ULONG
|
|
|
|
NTAPI
|
|
|
|
vDbgPrintEx(IN ULONG ComponentId,
|
|
|
|
IN ULONG Level,
|
2009-10-25 15:56:38 +00:00
|
|
|
IN PCCH Format,
|
2006-11-08 11:47:44 +00:00
|
|
|
IN va_list ap)
|
|
|
|
{
|
|
|
|
/* Call the internal routine that also handles ControlC */
|
2008-08-22 00:39:26 +00:00
|
|
|
return vDbgPrintExWithPrefixInternal("",
|
2006-11-08 11:47:44 +00:00
|
|
|
ComponentId,
|
|
|
|
Level,
|
|
|
|
Format,
|
|
|
|
ap,
|
|
|
|
TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
ULONG
|
|
|
|
__cdecl
|
|
|
|
DbgPrint(PCCH Format,
|
|
|
|
...)
|
|
|
|
{
|
2009-10-25 15:56:38 +00:00
|
|
|
ULONG Status;
|
2006-11-08 11:47:44 +00:00
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
/* Call the internal routine that also handles ControlC */
|
|
|
|
va_start(ap, Format);
|
2009-10-25 15:56:38 +00:00
|
|
|
Status = vDbgPrintExWithPrefixInternal("",
|
|
|
|
-1,
|
|
|
|
DPFLTR_ERROR_LEVEL,
|
|
|
|
Format,
|
|
|
|
ap,
|
|
|
|
TRUE);
|
2006-11-08 11:47:44 +00:00
|
|
|
va_end(ap);
|
2009-10-25 15:56:38 +00:00
|
|
|
return Status;
|
2006-11-08 11:47:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
ULONG
|
|
|
|
__cdecl
|
|
|
|
DbgPrintEx(IN ULONG ComponentId,
|
|
|
|
IN ULONG Level,
|
|
|
|
IN PCCH Format,
|
|
|
|
...)
|
|
|
|
{
|
2009-10-25 15:56:38 +00:00
|
|
|
ULONG Status;
|
2006-11-08 11:47:44 +00:00
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
/* Call the internal routine that also handles ControlC */
|
|
|
|
va_start(ap, Format);
|
2009-10-25 15:56:38 +00:00
|
|
|
Status = vDbgPrintExWithPrefixInternal("",
|
|
|
|
ComponentId,
|
|
|
|
Level,
|
|
|
|
Format,
|
|
|
|
ap,
|
|
|
|
TRUE);
|
2006-11-08 11:47:44 +00:00
|
|
|
va_end(ap);
|
2009-10-25 15:56:38 +00:00
|
|
|
return Status;
|
2006-11-08 11:47:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
ULONG
|
|
|
|
__cdecl
|
2009-10-25 15:56:38 +00:00
|
|
|
DbgPrintReturnControlC(PCCH Format,
|
2006-11-08 11:47:44 +00:00
|
|
|
...)
|
|
|
|
{
|
2009-10-25 15:56:38 +00:00
|
|
|
ULONG Status;
|
2006-11-08 11:47:44 +00:00
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
/* Call the internal routine that also handles ControlC */
|
|
|
|
va_start(ap, Format);
|
2009-10-25 15:56:38 +00:00
|
|
|
Status = vDbgPrintExWithPrefixInternal("",
|
|
|
|
-1,
|
|
|
|
DPFLTR_ERROR_LEVEL,
|
|
|
|
Format,
|
|
|
|
ap,
|
|
|
|
FALSE);
|
2008-10-29 20:06:44 +00:00
|
|
|
va_end(ap);
|
2009-10-25 15:56:38 +00:00
|
|
|
return Status;
|
2006-11-08 11:47:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
ULONG
|
|
|
|
NTAPI
|
2006-11-19 21:14:49 +00:00
|
|
|
DbgPrompt(IN PCCH Prompt,
|
|
|
|
OUT PCH Response,
|
|
|
|
IN ULONG MaximumResponseLength)
|
2006-11-08 11:47:44 +00:00
|
|
|
{
|
2009-10-25 15:56:38 +00:00
|
|
|
STRING Output;
|
2006-11-19 21:14:49 +00:00
|
|
|
STRING Input;
|
2006-11-08 11:47:44 +00:00
|
|
|
|
|
|
|
/* Setup the input string */
|
2007-03-02 07:21:33 +00:00
|
|
|
Input.MaximumLength = (USHORT)MaximumResponseLength;
|
2006-11-19 21:14:49 +00:00
|
|
|
Input.Buffer = Response;
|
2006-11-08 11:47:44 +00:00
|
|
|
|
|
|
|
/* Setup the output string */
|
2011-09-20 17:33:51 +00:00
|
|
|
Output.Length = (USHORT)strlen(Prompt);
|
2009-11-02 17:45:51 +00:00
|
|
|
Output.Buffer = (PCHAR)Prompt;
|
2006-11-08 11:47:44 +00:00
|
|
|
|
|
|
|
/* Call the system service */
|
|
|
|
return DebugPrompt(&Output, &Input);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2007-03-02 07:21:33 +00:00
|
|
|
NTSTATUS
|
2006-11-08 11:47:44 +00:00
|
|
|
NTAPI
|
|
|
|
DbgQueryDebugFilterState(IN ULONG ComponentId,
|
|
|
|
IN ULONG Level)
|
|
|
|
{
|
|
|
|
/* Call the Nt routine */
|
|
|
|
return NtQueryDebugFilterState(ComponentId, Level);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
DbgSetDebugFilterState(IN ULONG ComponentId,
|
|
|
|
IN ULONG Level,
|
|
|
|
IN BOOLEAN State)
|
|
|
|
{
|
|
|
|
/* Call the Nt routine */
|
|
|
|
return NtSetDebugFilterState(ComponentId, Level, State);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-01-24 19:48:34 +00:00
|
|
|
* @implemented
|
2006-11-08 11:47:44 +00:00
|
|
|
*/
|
2009-10-09 11:51:07 +00:00
|
|
|
VOID
|
2006-11-08 11:47:44 +00:00
|
|
|
NTAPI
|
2009-10-25 15:56:38 +00:00
|
|
|
DbgLoadImageSymbols(IN PSTRING Name,
|
2007-01-24 19:48:34 +00:00
|
|
|
IN PVOID Base,
|
2007-07-28 21:30:16 +00:00
|
|
|
IN ULONG_PTR ProcessId)
|
2006-11-08 11:47:44 +00:00
|
|
|
{
|
2007-01-24 19:48:34 +00:00
|
|
|
PIMAGE_NT_HEADERS NtHeader;
|
|
|
|
KD_SYMBOLS_INFO SymbolInfo;
|
|
|
|
|
|
|
|
/* Setup the symbol data */
|
|
|
|
SymbolInfo.BaseOfDll = Base;
|
2009-10-25 15:56:38 +00:00
|
|
|
SymbolInfo.ProcessId = ProcessId;
|
2007-01-24 19:48:34 +00:00
|
|
|
|
|
|
|
/* Get NT Headers */
|
2007-03-03 05:44:58 +00:00
|
|
|
NtHeader = RtlImageNtHeader(Base);
|
2007-01-24 19:48:34 +00:00
|
|
|
if (NtHeader)
|
|
|
|
{
|
|
|
|
/* Get the rest of the data */
|
|
|
|
SymbolInfo.CheckSum = NtHeader->OptionalHeader.CheckSum;
|
|
|
|
SymbolInfo.SizeOfImage = NtHeader->OptionalHeader.SizeOfImage;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* No data available */
|
2009-11-02 17:45:51 +00:00
|
|
|
SymbolInfo.CheckSum =
|
|
|
|
SymbolInfo.SizeOfImage = 0;
|
2007-01-24 19:48:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Load the symbols */
|
|
|
|
DebugService2(Name, &SymbolInfo, BREAKPOINT_LOAD_SYMBOLS);
|
2006-11-08 11:47:44 +00:00
|
|
|
}
|
2007-02-23 07:13:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
VOID
|
|
|
|
NTAPI
|
2009-10-25 15:56:38 +00:00
|
|
|
DbgUnLoadImageSymbols(IN PSTRING Name,
|
2007-02-23 07:13:19 +00:00
|
|
|
IN PVOID Base,
|
|
|
|
IN ULONG_PTR ProcessId)
|
|
|
|
{
|
|
|
|
KD_SYMBOLS_INFO SymbolInfo;
|
|
|
|
|
|
|
|
/* Setup the symbol data */
|
|
|
|
SymbolInfo.BaseOfDll = Base;
|
2009-10-25 15:56:38 +00:00
|
|
|
SymbolInfo.ProcessId = ProcessId;
|
2007-02-23 07:13:19 +00:00
|
|
|
SymbolInfo.CheckSum = SymbolInfo.SizeOfImage = 0;
|
|
|
|
|
|
|
|
/* Load the symbols */
|
|
|
|
DebugService2(Name, &SymbolInfo, BREAKPOINT_UNLOAD_SYMBOLS);
|
|
|
|
}
|
2009-11-02 17:45:51 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
DbgCommandString(IN PCCH Name,
|
|
|
|
IN PCCH Command)
|
|
|
|
{
|
|
|
|
STRING NameString, CommandString;
|
|
|
|
|
|
|
|
/* Setup the strings */
|
|
|
|
NameString.Buffer = (PCHAR)Name;
|
2011-09-20 17:33:51 +00:00
|
|
|
NameString.Length = (USHORT)strlen(Name);
|
2009-11-02 17:45:51 +00:00
|
|
|
CommandString.Buffer = (PCHAR)Command;
|
2011-09-20 17:33:51 +00:00
|
|
|
CommandString.Length = (USHORT)strlen(Command);
|
2009-11-02 17:45:51 +00:00
|
|
|
|
|
|
|
/* Send them to the debugger */
|
|
|
|
DebugService2(&NameString, &CommandString, BREAKPOINT_COMMAND_STRING);
|
|
|
|
}
|