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.

253 lines
5.8 KiB

  1. /*** trace.c - Trace functions
  2. *
  3. * This module contains all the debug functions.
  4. *
  5. * Copyright (c) 1996,1997 Microsoft Corporation
  6. * Author: Michael Tsang (MikeTs)
  7. * Created 09/24/96
  8. *
  9. * MODIFICATION HISTORY
  10. */
  11. #include "pch.h"
  12. #ifdef TRACING
  13. /*** Local function prototypes
  14. */
  15. VOID LOCAL TraceIndent(VOID);
  16. BOOLEAN LOCAL IsTrigPt(char *pszProcName);
  17. /*** Local data
  18. */
  19. int giTraceLevel = 0, giIndent = 0;
  20. char aszTrigPtBuff[MAX_TRIG_PTS][MAX_TRIGPT_LEN + 1] = {0};
  21. ULONG dwcTriggers = 0;
  22. /***EP IsTraceOn - Determine if tracing is on for the given procedure
  23. *
  24. * ENTRY
  25. * n - trace level
  26. * pszProcName -> procedure name
  27. * fEnter - TRUE if EnterProc trace
  28. *
  29. * EXIT-SUCCESS
  30. * returns TRUE
  31. * EXIT-FAILURE
  32. * returns FALSE
  33. */
  34. BOOLEAN EXPORT IsTraceOn(UCHAR n, char *pszProcName, BOOLEAN fEnter)
  35. {
  36. BOOLEAN rc = FALSE;
  37. if (!(gDebugger.dwfDebugger & (DBGF_IN_DEBUGGER | DBGF_CHECKING_TRACE)))
  38. {
  39. gDebugger.dwfDebugger |= DBGF_CHECKING_TRACE;
  40. if ((gDebugger.dwfDebugger & DBGF_TRIGGER_MODE) &&
  41. IsTrigPt(pszProcName))
  42. {
  43. if (fEnter)
  44. dwcTriggers++;
  45. else
  46. dwcTriggers--;
  47. rc = TRUE;
  48. }
  49. else if ((n <= giTraceLevel) &&
  50. (!(gDebugger.dwfDebugger & DBGF_TRIGGER_MODE) ||
  51. (dwcTriggers > 0)))
  52. {
  53. rc = TRUE;
  54. }
  55. if (rc == TRUE)
  56. TraceIndent();
  57. gDebugger.dwfDebugger &= ~DBGF_CHECKING_TRACE;
  58. }
  59. return rc;
  60. } //IsTraceOn
  61. /***LP IsTrigPt - Find the procedure name in the TrigPt buffer
  62. *
  63. * ENTRY
  64. * pszProcName -> procedure name
  65. *
  66. * EXIT-SUCCESS
  67. * returns TRUE - matched whole or partial name in the TrigPt buffer
  68. * EXIT-FAILURE
  69. * returns FALSE - no match
  70. */
  71. BOOLEAN LOCAL IsTrigPt(char *pszProcName)
  72. {
  73. BOOLEAN rc = FALSE;
  74. UCHAR i;
  75. for (i = 0; (rc == FALSE) && (i < MAX_TRIG_PTS); ++i)
  76. {
  77. if ((aszTrigPtBuff[i][0] != '\0') &&
  78. (STRSTR(pszProcName, &aszTrigPtBuff[i][0]) != NULL))
  79. {
  80. rc = TRUE;
  81. }
  82. }
  83. return rc;
  84. } //IsTrigPt
  85. /***LP TraceIndent - Indent trace output
  86. *
  87. * ENTRY
  88. * None
  89. *
  90. * EXIT
  91. * None
  92. */
  93. VOID LOCAL TraceIndent(VOID)
  94. {
  95. int i;
  96. PRINTF(MODNAME ":");
  97. for (i = 0; i < giIndent; i++)
  98. {
  99. PRINTF("| ");
  100. }
  101. } //TraceIndent
  102. /***LP SetTrace - set trace modes
  103. *
  104. * ENTRY
  105. * pArg -> argument type entry
  106. * pszArg -> argument string
  107. * dwArgNum - argument number
  108. * dwNonSWArgs - number of non-switch arguments
  109. *
  110. * EXIT
  111. * returns DBGERR_NONE
  112. */
  113. LONG LOCAL SetTrace(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum, ULONG dwNonSWArgs)
  114. {
  115. DEREF(pszArg);
  116. DEREF(dwNonSWArgs);
  117. //
  118. // User typed "set" without any arguments
  119. //
  120. if ((pArg == NULL) && (dwArgNum == 0))
  121. {
  122. int i;
  123. PRINTF("\nTrace Level = %d\n", giTraceLevel);
  124. PRINTF("Trace Trigger Mode = %s\n\n",
  125. gDebugger.dwfDebugger & DBGF_TRIGGER_MODE? "ON": "OFF");
  126. for (i = 0; i < MAX_TRIG_PTS; ++i)
  127. {
  128. PRINTF("%2d: %s\n", i, aszTrigPtBuff[i]);
  129. }
  130. }
  131. return DBGERR_NONE;
  132. } //SetTrace
  133. /***LP AddTraceTrigPts - Add trace trigger points
  134. *
  135. * ENTRY
  136. * pArg -> argument type entry
  137. * pszArg -> argument string
  138. * dwArgNum - argument number
  139. * dwNonSWArgs - number of non-switch arguments
  140. *
  141. * EXIT-SUCCESS
  142. * returns DBGERR_NONE
  143. * EXIT-FAILURE
  144. * returns negative error code
  145. */
  146. LONG LOCAL AddTraceTrigPts(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  147. ULONG dwNonSWArgs)
  148. {
  149. LONG rc = DBGERR_NONE;
  150. PSZ psz;
  151. int i;
  152. DEREF(pArg);
  153. DEREF(dwArgNum);
  154. DEREF(dwNonSWArgs);
  155. STRUPR(pszArg);
  156. if ((pszArg != NULL) && ((psz = STRTOK(pszArg, ",")) != NULL))
  157. {
  158. do
  159. {
  160. for (i = 0; i < MAX_TRIG_PTS; ++i)
  161. {
  162. if (aszTrigPtBuff[i][0] == '\0')
  163. {
  164. STRCPYN(aszTrigPtBuff[i], psz, MAX_TRIGPT_LEN + 1);
  165. break;
  166. }
  167. }
  168. if (i == MAX_TRIG_PTS)
  169. {
  170. DBG_ERROR(("no free trigger point - %s", psz));
  171. rc = DBGERR_CMD_FAILED;
  172. }
  173. } while ((rc == DBGERR_NONE) && ((psz = STRTOK(NULL, ",")) != NULL));
  174. }
  175. return rc;
  176. } //AddTraceTrigPts
  177. /***LP ZapTraceTrigPts - Zap trace trigger points
  178. *
  179. * ENTRY
  180. * pArg -> argument type entry
  181. * pszArg -> argument string
  182. * dwArgNum - argument number
  183. * dwNonSWArgs - number of non-switch arguments
  184. *
  185. * EXIT-SUCCESS
  186. * returns DBGERR_NONE
  187. * EXIT-FAILURE
  188. * returns negative error code
  189. */
  190. LONG LOCAL ZapTraceTrigPts(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  191. ULONG dwNonSWArgs)
  192. {
  193. LONG rc = DBGERR_NONE;
  194. PSZ psz, psz1;
  195. ULONG dwData;
  196. DEREF(pArg);
  197. DEREF(dwArgNum);
  198. DEREF(dwNonSWArgs);
  199. if ((pszArg != NULL) && ((psz = STRTOK(pszArg, ",")) != NULL))
  200. {
  201. do
  202. {
  203. dwData = STRTOUL(psz, &psz1, 10);
  204. if ((psz == psz1) || (dwData >= MAX_TRIG_PTS))
  205. {
  206. DBG_ERROR(("invalid trigger point - %d", dwData));
  207. rc = DBGERR_CMD_FAILED;
  208. }
  209. else
  210. aszTrigPtBuff[dwData][0] = '\0';
  211. } while ((rc == DBGERR_NONE) && ((psz = STRTOK(NULL, ",")) != NULL));
  212. }
  213. return rc;
  214. } //ZapTraceTrigPts
  215. #endif //ifdef TRACING