Source code of Windows XP (NT5)
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.

375 lines
7.6 KiB

  1. /*** debug.c - Debug functions
  2. *
  3. * This module contains all the debug functions.
  4. *
  5. * Author: Michael Tsang (MikeTs)
  6. * Created 10/08/97
  7. *
  8. * MODIFICATION HISTORY
  9. */
  10. #include "acpitabp.h"
  11. //Miscellaneous Constants
  12. #ifdef TRACING
  13. #define MAX_TRIG_PTS 10
  14. #define MAX_TRIGPT_LEN 31
  15. #define TF_TRIG_MODE 0x00000001
  16. #endif
  17. //Local function prototypes
  18. #ifdef TRACING
  19. VOID LOCAL TraceIndent(VOID);
  20. BOOL LOCAL IsTrigPt(char *pszProcName);
  21. PCHAR LOCAL InStr(PCHAR pszStr, PCHAR pszSubStr);
  22. VOID EXPORT DebugSetTraceLevel(VOID);
  23. VOID EXPORT DebugToggleTrigMode(VOID);
  24. VOID EXPORT DebugClearTrigPts(VOID);
  25. VOID EXPORT DebugAddTrigPt(VOID);
  26. VOID EXPORT DebugZapTrigPt(VOID);
  27. PCHAR LOCAL GetString(PCHAR pszPrompt, PCHAR pszBuff, BYTE bcLen, BOOL fUpper);
  28. #endif
  29. //Local Data
  30. #ifdef TRACING
  31. #pragma VXD_LOCKED_DATA
  32. int giTraceLevel = 0, giIndent = 0;
  33. char aszTrigPtBuff[MAX_TRIG_PTS][MAX_TRIGPT_LEN + 1] = {0};
  34. DWORD dwfTrace = 0, dwcTriggers = 0;
  35. #endif
  36. #ifdef DEBUGGER
  37. #pragma VXD_DEBUG_DATA
  38. CMDDC DebugCmds[] =
  39. {
  40. #ifdef TRACING
  41. {'t', DebugSetTraceLevel, "set Trace level ", "Set Trace Level"},
  42. {'g', DebugToggleTrigMode, "toGgle trigger mode ", "Toggle Trace Trigger mode"},
  43. {'x', DebugClearTrigPts, "clear trigger points", "Clear all trace trigger points"},
  44. {'y', DebugAddTrigPt, "add trigger point ", "Add a trace trigger point"},
  45. {'z', DebugZapTrigPt, "Zap trigger point ", "Delete a trace trigger point"},
  46. #endif
  47. {'q', NULL, "Quit ", "Quit the debugger"},
  48. {'\0'}
  49. };
  50. #endif //ifdef DEBUGGER
  51. #ifdef TRACING
  52. #pragma VXD_LOCKED_DATA
  53. #pragma VXD_LOCKED_CODE
  54. /***LP TraceIndent - Indent trace output
  55. *
  56. * ENTRY
  57. * None
  58. *
  59. * EXIT
  60. * None
  61. */
  62. VOID LOCAL TraceIndent(VOID)
  63. {
  64. int i;
  65. CMDD(WARNNAME ":");
  66. for (i = 0; i < giIndent; i++)
  67. {
  68. CMDD("..");
  69. }
  70. } //TraceIndent
  71. /***LP IsTraceOn - Determine if tracing is on for the given procedure
  72. *
  73. * ENTRY
  74. * n - trace level
  75. * pszProcName -> procedure name
  76. * fEnter - TRUE if EnterProc trace
  77. *
  78. * EXIT-SUCCESS
  79. * returns TRUE
  80. * EXIT-FAILURE
  81. * returns FALSE
  82. */
  83. BOOL LOCAL IsTraceOn(BYTE n, char *pszProcName, BOOL fEnter)
  84. {
  85. BOOL rc = FALSE;
  86. if ((dwfTrace & TF_TRIG_MODE) && IsTrigPt(pszProcName))
  87. {
  88. if (fEnter)
  89. dwcTriggers++;
  90. else
  91. dwcTriggers--;
  92. rc = TRUE;
  93. }
  94. else if ((n <= giTraceLevel) &&
  95. (!(dwfTrace & TF_TRIG_MODE) || (dwcTriggers > 0)))
  96. {
  97. rc = TRUE;
  98. }
  99. if (rc == TRUE)
  100. TraceIndent();
  101. return rc;
  102. } //IsTraceOn
  103. /***LP IsTrigPt - Find the procedure name in the TrigPt buffer
  104. *
  105. * ENTRY
  106. * pszProcName -> procedure name
  107. *
  108. * EXIT-SUCCESS
  109. * returns TRUE - matched whole or partial name in the TrigPt buffer
  110. * EXIT-FAILURE
  111. * returns FALSE - no match
  112. */
  113. BOOL LOCAL IsTrigPt(char *pszProcName)
  114. {
  115. BOOL rc = FALSE;
  116. BYTE i;
  117. for (i = 0; (rc == FALSE) && (i < MAX_TRIG_PTS); ++i)
  118. {
  119. if (InStr(pszProcName, &aszTrigPtBuff[i][0]) != NULL)
  120. rc = TRUE;
  121. }
  122. return rc;
  123. } //IsTrigPt
  124. /***LP InStr - Match a sub-string in a given string
  125. *
  126. * ENTRY
  127. * pszStr -> string
  128. * pszSubStr -> sub-string
  129. *
  130. * EXIT-SUCCESS
  131. * returns pointer to the string where the substring is found
  132. * EXIT-FAILURE
  133. * returns NULL
  134. */
  135. PCHAR LOCAL InStr(PCHAR pszStr, PCHAR pszSubStr)
  136. {
  137. PCHAR psz = NULL;
  138. BYTE bcStrLen = (BYTE)_lstrlen(pszStr);
  139. BYTE bcSubStrLen = (BYTE)_lstrlen(pszSubStr);
  140. _asm
  141. {
  142. cld
  143. mov edi,pszStr
  144. Next:
  145. mov esi,pszSubStr
  146. movzx ecx,BYTE PTR bcStrLen
  147. lodsb
  148. repne scasb
  149. jnz NotFound
  150. movzx ecx,BYTE PTR bcSubStrLen
  151. repe cmpsb
  152. jne Next
  153. movzx ecx,BYTE PTR bcSubStrLen
  154. sub edi,ecx
  155. mov psz,edi
  156. NotFound:
  157. }
  158. return psz;
  159. } //InStr
  160. #endif //ifdef TRACING
  161. #ifdef DEBUGGER
  162. #pragma VXD_DEBUG_DATA
  163. #pragma VXD_DEBUG_CODE
  164. /***EP ACPITabDebug - Debugger entry point
  165. *
  166. * ENTRY
  167. * None
  168. *
  169. * EXIT
  170. * None
  171. */
  172. VOID CM_SYSCTRL ACPITabDebug(VOID)
  173. {
  174. CMDMenu(WARNNAME, DebugCmds);
  175. } //ACPITabDebug
  176. #ifdef TRACING
  177. /***LP DebugSetTraceLevel - Set Trace Level
  178. *
  179. * ENTRY
  180. * None
  181. *
  182. * EXIT
  183. * None
  184. */
  185. VOID EXPORT DebugSetTraceLevel(VOID)
  186. {
  187. CMDD("\n");
  188. giTraceLevel = (int)CMDReadNumber("Trace Level", 1, FALSE);
  189. CMDD("\n\n");
  190. } //DebugSetTraceLevel
  191. /***LP DebugToggleTrigMode - Toggle Trace Trigger mode
  192. *
  193. * ENTRY
  194. * None
  195. *
  196. * EXIT
  197. * None
  198. */
  199. VOID EXPORT DebugToggleTrigMode(VOID)
  200. {
  201. dwfTrace ^= TF_TRIG_MODE;
  202. if (!(dwfTrace & TF_TRIG_MODE))
  203. dwcTriggers = 0;
  204. CMDD("\nTrace Trigger Mode is %s\n\n",
  205. (dwfTrace & TF_TRIG_MODE)? "On": "Off");
  206. } //DebugToggleTrigMode
  207. /***LP DebugClearTrigPts - Clear all trace trigger points
  208. *
  209. * ENTRY
  210. * None
  211. *
  212. * EXIT
  213. * None
  214. */
  215. VOID EXPORT DebugClearTrigPts(VOID)
  216. {
  217. BYTE i;
  218. for (i = 0; i < MAX_TRIG_PTS; ++i)
  219. aszTrigPtBuff[i][0] = '\0';
  220. CMDD("\n");
  221. } //DebugClearTrigPts
  222. /***LP DebugAddTrigPt - Add a trace trigger point
  223. *
  224. * ENTRY
  225. * None
  226. *
  227. * EXIT
  228. * None
  229. */
  230. VOID EXPORT DebugAddTrigPt(VOID)
  231. {
  232. char szTrigPt[MAX_TRIGPT_LEN + 1];
  233. BYTE i;
  234. CMDD("\n");
  235. GetString("Trigger Point", szTrigPt, sizeof(szTrigPt), TRUE);
  236. CMDD("\n");
  237. for (i = 0; i < MAX_TRIG_PTS; ++i)
  238. {
  239. if (aszTrigPtBuff[i][0] == '\0')
  240. {
  241. _lstrcpyn(aszTrigPtBuff[i], szTrigPt, MAX_TRIGPT_LEN + 1);
  242. break;
  243. }
  244. }
  245. if (i == MAX_TRIG_PTS)
  246. CMDD("No free trigger point.\n");
  247. CMDD("\n");
  248. } //DebugAddTrigPt
  249. /***LP DebugZapTrigPt - Delete a trace trigger point
  250. *
  251. * ENTRY
  252. * None
  253. *
  254. * EXIT
  255. * None
  256. */
  257. VOID EXPORT DebugZapTrigPt(VOID)
  258. {
  259. BYTE i, bcTrigPts;
  260. CMDD("\n");
  261. for (i = 0, bcTrigPts = 0; i < MAX_TRIG_PTS; ++i)
  262. {
  263. if (aszTrigPtBuff[i][0] != '\0')
  264. {
  265. CMDD("%2d: %s\n", i, &aszTrigPtBuff[i][0]);
  266. bcTrigPts++;
  267. }
  268. }
  269. if (bcTrigPts > 0)
  270. {
  271. CMDD("\n");
  272. i = (BYTE)CMDReadNumber("Trigger Point", 1, FALSE);
  273. CMDD("\n");
  274. if ((i < MAX_TRIG_PTS) && (aszTrigPtBuff[i][0] != '\0'))
  275. aszTrigPtBuff[i][0] = '\0';
  276. else
  277. CMDD("Invalid Trace Trigger Point.\n");
  278. }
  279. else
  280. CMDD("No Trace Trigger Point set.\n");
  281. CMDD("\n");
  282. } //DebugZapTrigPt
  283. /***LP GetString - Read a string from the debug terminal
  284. *
  285. * ENTRY
  286. * pszPrompt -> prompt string
  287. * pszBuff -> buffer to hold the string
  288. * bcLen - buffer length
  289. * fUpper - TRUE if convert to upper case
  290. *
  291. * EXIT
  292. * always returns pszBuff
  293. */
  294. PCHAR LOCAL GetString(PCHAR pszPrompt, PCHAR pszBuff, BYTE bcLen, BOOL fUpper)
  295. {
  296. BYTE i, ch;
  297. CMDD("%s: ", pszPrompt);
  298. for (i = 0; i < bcLen - 1; ++i)
  299. {
  300. ch = CMDInChar();
  301. if ((ch == '\r') || (ch == '\n'))
  302. break;
  303. else if (ch == '\b')
  304. {
  305. if (i > 0)
  306. i -= 2;
  307. }
  308. else if (fUpper && (ch >= 'a') && (ch <= 'z'))
  309. pszBuff[i] = (BYTE)(ch - 'a' + 'A');
  310. else if ((ch < ' ') || (ch > '~'))
  311. {
  312. ch = '\a'; //change it to a BELL character
  313. i--; //don't store it
  314. }
  315. else
  316. pszBuff[i] = ch;
  317. CMDD("%c", ch);
  318. }
  319. pszBuff[i] = '\0';
  320. return pszBuff;
  321. } //GetString
  322. #endif //ifdef TRACING
  323. #endif //ifdef DEBUGGER