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.

362 lines
16 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORP., 1997
  4. *
  5. * TITLE: DEBUG.C
  6. *
  7. * VERSION: 2.0
  8. *
  9. * AUTHOR: ReedB
  10. *
  11. * DATE: 21 Jan, 1997
  12. *
  13. * DESCRIPTION:
  14. *
  15. * Private debug routines implemented here.
  16. *
  17. *******************************************************************************/
  18. #include <nt.h>
  19. #include <ntrtl.h>
  20. #include <nturtl.h>
  21. #include <windows.h>
  22. #include <ntpoapi.h>
  23. #include <stdio.h>
  24. #include <powrprofp.h>
  25. #ifdef DEBUG
  26. LPTSTR lpszDebugPwrState[] = {
  27. TEXT("PwrSysUnspecified"),
  28. TEXT("S0, PwrSysWorking"),
  29. TEXT("S1, PwrSysSleeping1"),
  30. TEXT("S2, PwrSysSleeping2"),
  31. TEXT("S3, PwrSysSleeping3"),
  32. TEXT("S4, PwrSysHibernate"),
  33. TEXT("S5, PwrSysShutdown"),
  34. TEXT("PwrSysMaximum")
  35. };
  36. LPTSTR lpszDebugPwrAction[] = {
  37. TEXT("PwrActionNone"),
  38. TEXT("PwrActionDoze"),
  39. TEXT("PwrActionSleep"),
  40. TEXT("PwrActionHibernate"),
  41. TEXT("PwrActionShutdown"),
  42. TEXT("PwrActionShutdownReset"),
  43. TEXT("PwrActionShutdownOff")
  44. };
  45. extern int g_iShowValidationChanges;
  46. /*******************************************************************************
  47. *
  48. * GetIndent
  49. *
  50. * DESCRIPTION:
  51. *
  52. * PARAMETERS:
  53. *
  54. *******************************************************************************/
  55. #define MAX_INDENT 32
  56. void GetIndent(LPSTR lpsz, LPSTR lpszIndent)
  57. {
  58. UINT i;
  59. for (i = 0; i < MAX_INDENT; i++) {
  60. if (*lpsz != ' ') {
  61. break;
  62. }
  63. lpsz++;
  64. *lpszIndent++ = ' ';
  65. }
  66. *lpszIndent = '\0';
  67. }
  68. /*******************************************************************************
  69. *
  70. * DumpPowerActionPolicy
  71. *
  72. * DESCRIPTION:
  73. *
  74. * PARAMETERS:
  75. *
  76. *******************************************************************************/
  77. void DumpPowerActionPolicy(
  78. LPSTR lpszLabel,
  79. PPOWER_ACTION_POLICY ppap
  80. )
  81. {
  82. char szLabel[MAX_INDENT], szIndent[MAX_INDENT];
  83. GetIndent(lpszLabel, szIndent);
  84. MYDBGPRINT(("%s, POWER_ACTION_POLICY: %08X", lpszLabel, ppap));
  85. if (ppap->Action <= PowerActionShutdownOff) {
  86. MYDBGPRINT(("%s Action: %08X, %s", szIndent, ppap->Action, lpszDebugPwrAction[ppap->Action]));
  87. }
  88. else {
  89. MYDBGPRINT(("%s Action: %08X, Invalid!", szIndent, ppap->Action));
  90. }
  91. MYDBGPRINT(("%s Flags: %08X", szIndent, ppap->Flags));
  92. MYDBGPRINT(("%s EventCode: %08X", szIndent, ppap->EventCode));
  93. }
  94. /*******************************************************************************
  95. *
  96. * DumpSystemPowerLevel
  97. *
  98. * DESCRIPTION:
  99. *
  100. * PARAMETERS:
  101. *
  102. *******************************************************************************/
  103. void DumpSystemPowerLevel(
  104. LPSTR lpszLabel,
  105. PSYSTEM_POWER_LEVEL pspl
  106. )
  107. {
  108. char szLabel[MAX_INDENT], szIndent[MAX_INDENT];
  109. GetIndent(lpszLabel, szIndent);
  110. MYDBGPRINT(("%s, SYSTEM_POWER_LEVEL: %08X", lpszLabel, pspl));
  111. MYDBGPRINT(("%s Enable: %08X", szIndent, pspl->Enable));
  112. MYDBGPRINT(("%s BatteryLevel: %08X", szIndent, pspl->BatteryLevel));
  113. wsprintfA(szLabel, "%s PowerPolicy", szIndent);
  114. DumpPowerActionPolicy(szLabel, &pspl->PowerPolicy);
  115. if (pspl->MinSystemState <= PowerSystemMaximum) {
  116. MYDBGPRINT(("%s MinSystemState: %08X, %s", szIndent, pspl->MinSystemState, lpszDebugPwrState[pspl->MinSystemState]));
  117. }
  118. else {
  119. MYDBGPRINT(("%s MinSystemState: %08X, Invalid!!", szIndent, pspl->MinSystemState));
  120. }
  121. }
  122. /*******************************************************************************
  123. *
  124. * DumpSystemPowerPolicy
  125. *
  126. * DESCRIPTION:
  127. *
  128. * PARAMETERS:
  129. *
  130. *******************************************************************************/
  131. void DumpSystemPowerPolicy(
  132. LPSTR lpszLabel,
  133. PSYSTEM_POWER_POLICY pspp
  134. )
  135. {
  136. UINT i;
  137. char szLabel[MAX_INDENT], szIndent[MAX_INDENT];
  138. GetIndent(lpszLabel, szIndent);
  139. MYDBGPRINT(("%s, SYSTEM_POWER_POLICY: %08X", lpszLabel, pspp));
  140. MYDBGPRINT(("%s Revision: %08X", szIndent, pspp->Revision));
  141. wsprintfA(szLabel, "%s PowerButton", szIndent);
  142. DumpPowerActionPolicy( szLabel, &pspp->PowerButton);
  143. wsprintfA(szLabel, "%s SleepButton", szIndent);
  144. DumpPowerActionPolicy( szLabel, &pspp->SleepButton);
  145. wsprintfA(szLabel, "%s LidClose", szIndent);
  146. DumpPowerActionPolicy( szLabel, &pspp->LidClose);
  147. MYDBGPRINT(("%s LidOpenWake: %08X, %s", szIndent, pspp->LidOpenWake, lpszDebugPwrState[pspp->LidOpenWake]));
  148. wsprintfA(szLabel, "%s Idle", szIndent);
  149. DumpPowerActionPolicy( szLabel, &pspp->Idle);
  150. MYDBGPRINT(("%s IdleTimeout: %08X", szIndent, pspp->IdleTimeout));
  151. MYDBGPRINT(("%s IdleSensitivity: %08X", szIndent, pspp->IdleSensitivity));
  152. MYDBGPRINT(("%s MinSleep: %08X, %s", szIndent, pspp->MinSleep, lpszDebugPwrState[pspp->MinSleep]));
  153. MYDBGPRINT(("%s MaxSleep: %08X, %s", szIndent, pspp->MaxSleep, lpszDebugPwrState[pspp->MaxSleep]));
  154. MYDBGPRINT(("%s ReducedLatencySleep: %08X, %s", szIndent, pspp->ReducedLatencySleep, lpszDebugPwrState[pspp->ReducedLatencySleep]));
  155. MYDBGPRINT(("%s WinLogonFlags: %08X", szIndent, pspp->WinLogonFlags));
  156. MYDBGPRINT(("%s DozeS4Timeout: %08X", szIndent, pspp->DozeS4Timeout));
  157. MYDBGPRINT(("%s BroadcastCapacityResolution: %08X", szIndent, pspp->BroadcastCapacityResolution));
  158. for (i = 0; i < NUM_DISCHARGE_POLICIES; i++) {
  159. wsprintfA(szLabel, "%s DischargePolicy[%d]", szIndent, i);
  160. DumpSystemPowerLevel( szLabel, &pspp->DischargePolicy[i]);
  161. }
  162. MYDBGPRINT(("%s VideoTimeout: %08X", szIndent, pspp->VideoTimeout));
  163. MYDBGPRINT(("%s VideoDimDisplay: %08X", szIndent, pspp->VideoDimDisplay));
  164. MYDBGPRINT(("%s SpindownTimeout: %08X", szIndent, pspp->SpindownTimeout));
  165. MYDBGPRINT(("%s OptimizeForPower: %08X", szIndent, pspp->OptimizeForPower));
  166. MYDBGPRINT(("%s FanThrottleTolerance: %08X", szIndent, pspp->FanThrottleTolerance));
  167. MYDBGPRINT(("%s ForcedThrottle: %08X", szIndent, pspp->ForcedThrottle));
  168. MYDBGPRINT(("%s MinThrottle: %08X", szIndent, pspp->MinThrottle));
  169. wsprintfA(szLabel, "%s OverThrottled", szIndent);
  170. DumpPowerActionPolicy( szLabel, &pspp->OverThrottled);
  171. MYDBGPRINT(("\n\n"));
  172. }
  173. /*******************************************************************************
  174. *
  175. * DumpSystemPowerCapabilities
  176. *
  177. * DESCRIPTION:
  178. *
  179. * PARAMETERS:
  180. *
  181. *******************************************************************************/
  182. void DumpSystemPowerCapabilities(
  183. LPSTR lpszLabel,
  184. PSYSTEM_POWER_CAPABILITIES pspc
  185. )
  186. {
  187. UINT i;
  188. char szLabel[MAX_INDENT], szIndent[MAX_INDENT];
  189. GetIndent(lpszLabel, szIndent);
  190. MYDBGPRINT(("%s, SYSTEM_POWER_CAPABILITIES: %08X", lpszLabel, pspc));
  191. MYDBGPRINT(("%s PowerButtonPresent: %08X", szIndent, pspc->PowerButtonPresent));
  192. MYDBGPRINT(("%s SleepButtonPresent: %08X", szIndent, pspc->SleepButtonPresent));
  193. MYDBGPRINT(("%s LidPresent: %08X", szIndent, pspc->LidPresent));
  194. MYDBGPRINT(("%s SystemS1: %08X", szIndent, pspc->SystemS1));
  195. MYDBGPRINT(("%s SystemS2: %08X", szIndent, pspc->SystemS2));
  196. MYDBGPRINT(("%s SystemS3: %08X", szIndent, pspc->SystemS3));
  197. MYDBGPRINT(("%s SystemS4: %08X", szIndent, pspc->SystemS4));
  198. MYDBGPRINT(("%s SystemS5: %08X", szIndent, pspc->SystemS5));
  199. MYDBGPRINT(("%s HiberFilePresent: %08X", szIndent, pspc->HiberFilePresent));
  200. MYDBGPRINT(("%s ThermalControl: %08X", szIndent, pspc->ThermalControl));
  201. MYDBGPRINT(("%s ProcessorThrottle: %08X", szIndent, pspc->ProcessorThrottle));
  202. MYDBGPRINT(("%s ProcessorMinThrottle: %02X", szIndent, pspc->ProcessorMinThrottle));
  203. MYDBGPRINT(("%s ProcessorMaxThrottle: %02X", szIndent, pspc->ProcessorMaxThrottle));
  204. MYDBGPRINT(("%s VideoDimPresent: %08X", szIndent, pspc->VideoDimPresent));
  205. MYDBGPRINT(("%s DiskSpinDown: %08X", szIndent, pspc->DiskSpinDown));
  206. MYDBGPRINT(("%s SystemBatteriesPresent: %08X", szIndent, pspc->SystemBatteriesPresent));
  207. MYDBGPRINT(("%s BatteriesAreShortTerm: %08X", szIndent, pspc->BatteriesAreShortTerm));
  208. // Not implemented: BATTERY_REPORTING_SCALE BatteryScale[3];
  209. MYDBGPRINT(("%s AcOnLineWake: %08X, %s", szIndent, pspc->AcOnLineWake, lpszDebugPwrState[pspc->AcOnLineWake]));
  210. MYDBGPRINT(("%s SoftLidWake: %08X, %s", szIndent, pspc->SoftLidWake, lpszDebugPwrState[pspc->SoftLidWake]));
  211. MYDBGPRINT(("%s RtcWake: %08X, %s", szIndent, pspc->RtcWake, lpszDebugPwrState[pspc->RtcWake]));
  212. MYDBGPRINT(("%s MinDeviceWakeState: %08X, %s", szIndent, pspc->MinDeviceWakeState, lpszDebugPwrState[pspc->MinDeviceWakeState]));
  213. MYDBGPRINT(("%s DefaultLowLatencyWake: %08X, %s", szIndent, pspc->DefaultLowLatencyWake, lpszDebugPwrState[pspc->DefaultLowLatencyWake]));
  214. MYDBGPRINT(("\n\n"));
  215. }
  216. /*******************************************************************************
  217. *
  218. * DifSystemPowerPolicies
  219. *
  220. * DESCRIPTION:
  221. *
  222. * PARAMETERS:
  223. *
  224. *******************************************************************************/
  225. void DifSystemPowerPolicies(
  226. LPSTR lpszLabel,
  227. PSYSTEM_POWER_POLICY pspp1,
  228. PSYSTEM_POWER_POLICY pspp2
  229. )
  230. {
  231. UINT i;
  232. char szLabel[MAX_INDENT], szIndent[MAX_INDENT];
  233. if (!g_iShowValidationChanges) {
  234. return;
  235. }
  236. if (memcmp(pspp1, pspp2, sizeof(SYSTEM_POWER_POLICY))) {
  237. GetIndent(lpszLabel, szIndent);
  238. MYDBGPRINT(("%s, spp1: %08X, spp2: %08X", lpszLabel, pspp1, pspp2));
  239. if (pspp1->Revision != pspp2->Revision) {
  240. MYDBGPRINT(("%s Revision, spp1: %08X, spp2: %08X", szIndent, pspp1->Revision, pspp2->Revision));
  241. }
  242. if (memcmp(&pspp1->PowerButton, &pspp2->PowerButton, sizeof(POWER_ACTION_POLICY))) {
  243. wsprintfA(szLabel, "%s spp1, PowerButton", szIndent);
  244. DumpPowerActionPolicy( szLabel, &pspp1->PowerButton);
  245. wsprintfA(szLabel, "%s spp2, PowerButton", szIndent);
  246. DumpPowerActionPolicy( szLabel, &pspp2->PowerButton);
  247. }
  248. if (memcmp(&pspp1->SleepButton, &pspp2->SleepButton, sizeof(POWER_ACTION_POLICY))) {
  249. wsprintfA(szLabel, "%s spp1, SleepButton", szIndent);
  250. DumpPowerActionPolicy( szLabel, &pspp1->SleepButton);
  251. wsprintfA(szLabel, "%s spp2, SleepButton", szIndent);
  252. DumpPowerActionPolicy( szLabel, &pspp2->SleepButton);
  253. }
  254. if (memcmp(&pspp1->LidClose, &pspp2->LidClose, sizeof(POWER_ACTION_POLICY))) {
  255. wsprintfA(szLabel, "%s spp1, LidClose", szIndent);
  256. DumpPowerActionPolicy( szLabel, &pspp1->LidClose);
  257. wsprintfA(szLabel, "%s spp2, LidClose:", szIndent);
  258. DumpPowerActionPolicy( szLabel, &pspp2->LidClose);
  259. }
  260. if (pspp1->LidOpenWake != pspp2->LidOpenWake) {
  261. MYDBGPRINT(("%s spp1, LidOpenWake: %08X, %s", szIndent, pspp1->LidOpenWake, lpszDebugPwrState[pspp1->LidOpenWake]));
  262. MYDBGPRINT(("%s spp2, LidOpenWake: %08X, %s", szIndent, pspp2->LidOpenWake, lpszDebugPwrState[pspp2->LidOpenWake]));
  263. }
  264. if (memcmp(&pspp1->Idle, &pspp2->Idle, sizeof(POWER_ACTION_POLICY))) {
  265. wsprintfA(szLabel, "%s spp1, Idle", szIndent);
  266. DumpPowerActionPolicy( szLabel, &pspp1->Idle);
  267. wsprintfA(szLabel, "%s spp2, Idle", szIndent);
  268. DumpPowerActionPolicy( szLabel, &pspp2->Idle);
  269. }
  270. if (pspp1->IdleTimeout != pspp2->IdleTimeout) {
  271. MYDBGPRINT(("%s IdleTimeout, spp1: %08X, spp2: %08X", szIndent, pspp1->IdleTimeout, pspp2->IdleTimeout));
  272. }
  273. if (pspp1->IdleSensitivity != pspp2->IdleSensitivity) {
  274. MYDBGPRINT(("%s IdleSensitivity, spp1: %08X, spp2: %08X", szIndent, pspp1->IdleSensitivity, pspp2->IdleSensitivity));
  275. }
  276. if (pspp1->MinSleep != pspp2->MinSleep) {
  277. MYDBGPRINT(("%s MinSleep, spp1: %08X, %s", szIndent, pspp1->MinSleep, lpszDebugPwrState[pspp1->MinSleep]));
  278. MYDBGPRINT(("%s MinSleep, spp2: %08X, %s", szIndent, pspp2->MinSleep, lpszDebugPwrState[pspp2->MinSleep]));
  279. }
  280. if (pspp1->MaxSleep != pspp2->MaxSleep) {
  281. MYDBGPRINT(("%s MaxSleep, spp1: %08X, %s", szIndent, pspp1->MaxSleep, lpszDebugPwrState[pspp1->MaxSleep]));
  282. MYDBGPRINT(("%s MaxSleep, spp2: %08X, %s", szIndent, pspp2->MaxSleep, lpszDebugPwrState[pspp2->MaxSleep]));
  283. }
  284. if (pspp1->ReducedLatencySleep != pspp2->ReducedLatencySleep) {
  285. MYDBGPRINT(("%s ReducedLatencySleep, spp1: %08X, %s", szIndent, pspp1->ReducedLatencySleep, lpszDebugPwrState[pspp1->ReducedLatencySleep]));
  286. MYDBGPRINT(("%s ReducedLatencySleep, spp2: %08X, %s", szIndent, pspp2->ReducedLatencySleep, lpszDebugPwrState[pspp2->ReducedLatencySleep]));
  287. }
  288. if (pspp1->WinLogonFlags != pspp2->WinLogonFlags) {
  289. MYDBGPRINT(("%s WinLogonFlags, spp1: %08X, spp2: %08X", szIndent, pspp1->WinLogonFlags, pspp2->WinLogonFlags));
  290. }
  291. if (pspp1->DozeS4Timeout != pspp2->DozeS4Timeout) {
  292. MYDBGPRINT(("%s DozeS4Timeout, spp1: %08X, spp2: %08X", szIndent, pspp1->DozeS4Timeout, pspp2->DozeS4Timeout));
  293. }
  294. if (pspp1->BroadcastCapacityResolution != pspp2->BroadcastCapacityResolution) {
  295. MYDBGPRINT(("%s BroadcastCapacityResolution, spp1: %08X, spp2: %08X", szIndent, pspp1->BroadcastCapacityResolution, pspp2->BroadcastCapacityResolution));
  296. }
  297. for (i = 0; i < NUM_DISCHARGE_POLICIES; i++) {
  298. if (memcmp(&(pspp1->DischargePolicy[i]), &(pspp2->DischargePolicy[i]), sizeof(SYSTEM_POWER_LEVEL))) {
  299. wsprintfA(szLabel, "%s DischargePolicy[%d], spp1:", szIndent, i);
  300. DumpSystemPowerLevel( szLabel, &pspp1->DischargePolicy[i]);
  301. wsprintfA(szLabel, "%s DischargePolicy[%d], spp2:", szIndent, i);
  302. DumpSystemPowerLevel( szLabel, &pspp2->DischargePolicy[i]);
  303. }
  304. }
  305. if (pspp1->VideoTimeout != pspp2->VideoTimeout) {
  306. MYDBGPRINT(("%s VideoTimeout, spp1: %08X, spp2: %08X", szIndent, pspp1->VideoTimeout, pspp2->VideoTimeout));
  307. }
  308. if (pspp1->VideoDimDisplay != pspp2->VideoDimDisplay) {
  309. MYDBGPRINT(("%s VideoDimDisplay, spp1: %08X, spp2: %08X", szIndent, pspp1->VideoDimDisplay, pspp2->VideoDimDisplay));
  310. }
  311. if (pspp1->SpindownTimeout != pspp2->SpindownTimeout) {
  312. MYDBGPRINT(("%s SpindownTimeout, spp1: %08X, spp2: %08X", szIndent, pspp1->SpindownTimeout, pspp2->SpindownTimeout));
  313. }
  314. if (pspp1->OptimizeForPower != pspp2->OptimizeForPower) {
  315. MYDBGPRINT(("%s OptimizeForPower, spp1: %08X, spp2: %08X", szIndent, pspp1->OptimizeForPower, pspp2->OptimizeForPower));
  316. }
  317. if (pspp1->FanThrottleTolerance != pspp2->FanThrottleTolerance) {
  318. MYDBGPRINT(("%s FanThrottleTolerance, spp1: %08X, spp2: %08X", szIndent, pspp1->FanThrottleTolerance, pspp2->FanThrottleTolerance));
  319. }
  320. if (pspp1->ForcedThrottle != pspp2->ForcedThrottle) {
  321. MYDBGPRINT(("%s ForcedThrottle, spp1: %08X, spp2: %08X", szIndent, pspp1->ForcedThrottle, pspp2->ForcedThrottle));
  322. }
  323. if (pspp1->MinThrottle != pspp2->MinThrottle) {
  324. MYDBGPRINT(("%s MinThrottle, spp1: %08X, spp2: %08X", szIndent, pspp1->MinThrottle, pspp2->MinThrottle));
  325. }
  326. if (memcmp(&pspp1->OverThrottled, &pspp2->OverThrottled, sizeof(POWER_ACTION_POLICY))) {
  327. wsprintfA(szLabel, "%s spp1, OverThrottled", szIndent);
  328. DumpPowerActionPolicy( szLabel, &pspp1->OverThrottled);
  329. wsprintfA(szLabel, "%s spp2, OverThrottled", szIndent);
  330. DumpPowerActionPolicy( szLabel, &pspp2->OverThrottled);
  331. }
  332. MYDBGPRINT(("\n\n"));
  333. }
  334. }
  335. #endif