Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

330 lines
5.5 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. debug.c
  5. Abstract:
  6. Debugging routines exported by the STOR library.
  7. Author:
  8. Matthew D Hendel (math) 29-Apr-2000
  9. Revision History:
  10. --*/
  11. #include "precomp.h"
  12. //#include "ntrtl.h"
  13. #if DBG
  14. BOOLEAN StorQuiet = FALSE;
  15. ULONG StorComponentId = -1;
  16. PCSTR StorDebugPrefix = "STOR: ";
  17. //
  18. // NB: These should come from ntrtl.h
  19. //
  20. ULONG
  21. vDbgPrintExWithPrefix(
  22. IN PCH Prefix,
  23. IN ULONG ComponentId,
  24. IN ULONG Level,
  25. IN PCSTR Format,
  26. va_list arglist
  27. );
  28. NTSYSAPI
  29. ULONG
  30. NTAPI
  31. DbgPrompt(
  32. PCH Prompt,
  33. PCH Response,
  34. ULONG MaximumResponseLength
  35. );
  36. BOOLEAN
  37. StorAssertHelper(
  38. PCHAR Expression,
  39. PCHAR File,
  40. ULONG Line,
  41. PBOOLEAN Ignore
  42. )
  43. {
  44. CHAR Response[2];
  45. DebugPrint (("*** Assertion failed: %s\n", Expression));
  46. DebugPrint (("*** Source File: %s, line %ld\n\n", File, Line));
  47. if (*Ignore == TRUE) {
  48. DebugPrint (("Ignored\n"));
  49. return FALSE;
  50. }
  51. for (;;) {
  52. //
  53. // The following line will print the prefix, not just the space.
  54. //
  55. DebugPrint ((" "));
  56. DbgPrompt( "(B)reak, (S)kip (I)gnore (bsi)? ",
  57. Response,
  58. sizeof (Response) );
  59. switch (tolower (Response[0])) {
  60. case 'b':
  61. return TRUE;
  62. case 'i':
  63. *Ignore = TRUE;
  64. return FALSE;
  65. case 's':
  66. return FALSE;
  67. }
  68. }
  69. }
  70. VOID
  71. StorSetDebugPrefixAndId(
  72. IN PCSTR Prefix,
  73. IN ULONG ComponentId
  74. )
  75. /*++
  76. Routine Description:
  77. Set the default debug prefix to something other than "STOR: ".
  78. Arguments:
  79. Prefix - Supplies the prefix. The pointer to the prefix is saved
  80. preserved, so the prefix memory cannot be paged deallocated.
  81. Generally, using a static string here is best.
  82. ComponentId -
  83. Return Value:
  84. None.
  85. --*/
  86. {
  87. StorDebugPrefix = Prefix;
  88. StorComponentId = ComponentId;
  89. }
  90. VOID
  91. vStorDebugPrintEx(
  92. IN ULONG Level,
  93. IN PCSTR Format,
  94. va_list arglist
  95. )
  96. {
  97. if (Level == DPFLTR_ERROR_LEVEL || !StorQuiet) {
  98. vDbgPrintExWithPrefix ((PSTR)StorDebugPrefix,
  99. StorComponentId,
  100. Level,
  101. Format,
  102. arglist);
  103. }
  104. }
  105. VOID
  106. StorDebugPrintEx(
  107. IN ULONG Level,
  108. IN PCSTR Format,
  109. ...
  110. )
  111. {
  112. va_list ap;
  113. va_start (ap, Format);
  114. vStorDebugPrintEx (Level, Format, ap);
  115. va_end (ap);
  116. }
  117. VOID
  118. StorDebugWarn(
  119. IN PCSTR Format,
  120. ...
  121. )
  122. {
  123. va_list ap;
  124. va_start (ap, Format);
  125. vStorDebugPrintEx (DPFLTR_WARNING_LEVEL,
  126. Format,
  127. ap);
  128. va_end (ap);
  129. }
  130. VOID
  131. StorDebugTrace(
  132. IN PCSTR Format,
  133. ...
  134. )
  135. {
  136. va_list ap;
  137. va_start (ap, Format);
  138. vStorDebugPrintEx (DPFLTR_TRACE_LEVEL,
  139. Format,
  140. ap);
  141. va_end (ap);
  142. }
  143. VOID
  144. StorDebugPrint(
  145. IN PCSTR Format,
  146. ...
  147. )
  148. {
  149. va_list ap;
  150. va_start (ap, Format);
  151. vStorDebugPrintEx (DPFLTR_ERROR_LEVEL,
  152. Format,
  153. ap);
  154. va_end (ap);
  155. }
  156. #endif // DBG
  157. //
  158. // The following are support functions for compiler runtime checks.
  159. //
  160. #if defined (_RTC) || (DBG == 1)
  161. typedef struct _RTC_vardesc {
  162. int addr;
  163. int size;
  164. char *name;
  165. } _RTC_vardesc;
  166. typedef struct _RTC_framedesc {
  167. int varCount;
  168. _RTC_vardesc *variables;
  169. } _RTC_framedesc;
  170. VOID
  171. __cdecl
  172. _RTC_InitBase(
  173. VOID
  174. )
  175. {
  176. }
  177. VOID
  178. __cdecl
  179. _RTC_Shutdown(
  180. VOID
  181. )
  182. {
  183. }
  184. VOID
  185. #if defined (_X86_)
  186. __declspec(naked)
  187. #endif // _X86_
  188. __cdecl
  189. _RTC_CheckEsp(
  190. )
  191. {
  192. #if defined (_X86_)
  193. __asm {
  194. jne esperror ;
  195. ret
  196. esperror:
  197. ; function prolog
  198. push ebp
  199. mov ebp, esp
  200. sub esp, __LOCAL_SIZE
  201. push eax ; save the old return value
  202. push edx
  203. push ebx
  204. push esi
  205. push edi
  206. }
  207. DebugPrint (("*** Callstack Check failure at %p\n", _ReturnAddress()));
  208. KdBreakPoint();
  209. __asm {
  210. ; function epilog
  211. pop edi
  212. pop esi
  213. pop ebx
  214. pop edx ; restore the old return value
  215. pop eax
  216. mov esp, ebp
  217. pop ebp
  218. ret
  219. }
  220. #endif
  221. }
  222. VOID
  223. FASTCALL
  224. _RTC_CheckStackVars(
  225. PVOID frame,
  226. _RTC_framedesc *v
  227. )
  228. {
  229. int i;
  230. for (i = 0; i < v->varCount; i++) {
  231. int *head = (int *)(((char *)frame) + v->variables[i].addr + v->variables[i].size);
  232. int *tail = (int *)(((char *)frame) + v->variables[i].addr - sizeof(int));
  233. if (*tail != 0xcccccccc || *head != 0xcccccccc) {
  234. DebugPrint(("*** RTC Failure %p: stack corruption near %p (%s)\n",
  235. _ReturnAddress(),
  236. v->variables[i].addr + (ULONG_PTR)frame,
  237. v->variables[i].name));
  238. KdBreakPoint();
  239. }
  240. }
  241. }
  242. VOID
  243. __cdecl
  244. _RTC_UninitUse(
  245. IN PCSTR varname
  246. )
  247. {
  248. DebugPrint(("\n*** RTC Failure %p: uninitialized variable %s.\n",
  249. _ReturnAddress(),
  250. varname));
  251. KdBreakPoint();
  252. }
  253. #endif // _RTC || DBG