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.

626 lines
13 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. log.c
  5. Abstract:
  6. WinDbg Extension Api
  7. implements !_log
  8. Author:
  9. jd
  10. Environment:
  11. User Mode.
  12. Revision History:
  13. --*/
  14. #include "precomp.h"
  15. #include "usbhcdkd.h"
  16. VOID
  17. DumpXferLog(
  18. MEMLOC LogMemLoc,
  19. MEMLOC StartMemLoc,
  20. MEMLOC EndMemLoc,
  21. ULONG NumEntriesToDump
  22. )
  23. {
  24. ULONG i;
  25. LOG_ENTRY logEntry1, logEntry2;
  26. ULONG cb;
  27. MEMLOC m1, m2, m3;
  28. ENDPOINT_TRANSFER_TYPE t;
  29. PUCHAR s;
  30. PrintfMemLoc("*TRANSFER LOGSTART: ", LogMemLoc, " ");
  31. dprintf("# %d \n", NumEntriesToDump);
  32. for (i=0; i< NumEntriesToDump; i++) {
  33. ReadMemory(LogMemLoc,
  34. &logEntry2,
  35. sizeof(logEntry2),
  36. &cb);
  37. LogMemLoc+=cb;
  38. if (LogMemLoc > EndMemLoc) {
  39. LogMemLoc = StartMemLoc;
  40. }
  41. ReadMemory(LogMemLoc,
  42. &logEntry1,
  43. sizeof(logEntry1),
  44. &cb);
  45. LogMemLoc+=cb;
  46. if (LogMemLoc > EndMemLoc) {
  47. LogMemLoc = StartMemLoc;
  48. }
  49. #if 0
  50. t = (ENDPOINT_TRANSFER_TYPE) logEntry.TransferType;
  51. switch(logEntry.TransferType) {
  52. case Isochronous:
  53. s = "ISO";
  54. break;
  55. case Control:
  56. s = "CON";
  57. break;
  58. case Bulk:
  59. s = "BLK";
  60. break;
  61. case Interrupt:
  62. s = "INT";
  63. break;
  64. default:
  65. s = "???";
  66. }
  67. #endif
  68. dprintf("[%3.3d] Endpoint(%08.8x) - URB:%08.8x IRP:%8.8x\n",
  69. i,
  70. logEntry1.le_info1,
  71. logEntry1.le_info2,
  72. logEntry1.le_info3);
  73. dprintf(" \t\t\t Bytes [%6.6d] NT_STATUS %08.8x USBD_STATUS %08.8x\n",
  74. logEntry2.le_info3,
  75. logEntry2.le_info2,
  76. logEntry2.le_info1);
  77. }
  78. }
  79. VOID
  80. DumpLog(
  81. MEMLOC LogMemLoc,
  82. MEMLOC StartMemLoc,
  83. MEMLOC EndMemLoc,
  84. ULONG NumEntriesToDump,
  85. ULONG MarkSig1,
  86. ULONG MarkSig2
  87. )
  88. {
  89. ULONG i;
  90. SIG s;
  91. LOG_ENTRY64 logEntry64;
  92. LOG_ENTRY32 logEntry32;
  93. CHAR c;
  94. ULONG cb;
  95. MEMLOC m1, m2, m3;
  96. PrintfMemLoc("*LOG: ", LogMemLoc, " ");
  97. PrintfMemLoc("*LOGSTART: ", StartMemLoc, " ");
  98. PrintfMemLoc("*LOGEND: ", EndMemLoc, " ");
  99. dprintf("# %d \n", NumEntriesToDump);
  100. #if 0
  101. s.l = MarkSig1;
  102. dprintf("*(%c%c%c%c) ",
  103. s.c[0], s.c[1], s.c[2], s.c[3]);
  104. s.l = MarkSig2;
  105. dprintf("*(%c%c%c%c) ",
  106. s.c[0], s.c[1], s.c[2], s.c[3]);
  107. dprintf("\n");
  108. #endif
  109. for (i=0; i< NumEntriesToDump; i++) {
  110. if (IsPtr64()) {
  111. ReadMemory(LogMemLoc,
  112. &logEntry64,
  113. sizeof(logEntry64),
  114. &cb);
  115. s.l = logEntry64.le_sig;
  116. m1 = logEntry64.le_info1;
  117. m2 = logEntry64.le_info2;
  118. m3 = logEntry64.le_info3;
  119. } else {
  120. ReadMemory(LogMemLoc,
  121. &logEntry32,
  122. sizeof(logEntry32),
  123. &cb);
  124. s.l = logEntry32.le_sig;
  125. m1 = logEntry32.le_info1;
  126. m2 = logEntry32.le_info2;
  127. m3 = logEntry32.le_info3;
  128. }
  129. if (s.l == MarkSig1 || s.l == MarkSig2) {
  130. c = '*';
  131. } else {
  132. c = ' ';
  133. }
  134. dprintf("%c[%3.3d]", c, i);
  135. PrintfMemLoc(" ", LogMemLoc, " ");
  136. dprintf("%c%c%c%c ", s.c[0], s.c[1], s.c[2], s.c[3]);
  137. PrintfMemLoc(" ", m1, " ");
  138. PrintfMemLoc(" ", m2, " ");
  139. PrintfMemLoc(" ", m3, "\n");
  140. LogMemLoc+=cb;
  141. if (LogMemLoc > EndMemLoc) {
  142. LogMemLoc = StartMemLoc;
  143. }
  144. }
  145. }
  146. VOID
  147. DumpEnumLog(
  148. MEMLOC LogMemLoc,
  149. MEMLOC StartMemLoc,
  150. MEMLOC EndMemLoc,
  151. ULONG NumEntriesToDump
  152. )
  153. {
  154. ULONG i;
  155. SIG s;
  156. LOG_ENTRY64 logEntry64;
  157. LOG_ENTRY32 logEntry32;
  158. CHAR c;
  159. ULONG cb;
  160. MEMLOC m1, m2, m3;
  161. PrintfMemLoc("*LOG: ", LogMemLoc, " ");
  162. PrintfMemLoc("*LOGSTART: ", StartMemLoc, " ");
  163. PrintfMemLoc("*LOGEND: ", EndMemLoc, " ");
  164. dprintf("# %d \n", NumEntriesToDump);
  165. #if 0
  166. s.l = MarkSig1;
  167. dprintf("*(%c%c%c%c) ",
  168. s.c[0], s.c[1], s.c[2], s.c[3]);
  169. s.l = MarkSig2;
  170. dprintf("*(%c%c%c%c) ",
  171. s.c[0], s.c[1], s.c[2], s.c[3]);
  172. dprintf("\n");
  173. #endif
  174. for (i=0; i< NumEntriesToDump; i++) {
  175. if (IsPtr64()) {
  176. ReadMemory(LogMemLoc,
  177. &logEntry64,
  178. sizeof(logEntry64),
  179. &cb);
  180. s.l = logEntry64.le_sig;
  181. m1 = logEntry64.le_info1;
  182. m2 = logEntry64.le_info2;
  183. m3 = logEntry64.le_info3;
  184. } else {
  185. ReadMemory(LogMemLoc,
  186. &logEntry32,
  187. sizeof(logEntry32),
  188. &cb);
  189. s.l = logEntry32.le_sig;
  190. m1 = logEntry32.le_info1;
  191. m2 = logEntry32.le_info2;
  192. m3 = logEntry32.le_info3;
  193. }
  194. // if (s.l == MarkSig1 || s.l == MarkSig2) {
  195. // c = '*';
  196. // } else {
  197. // c = ' ';
  198. // }
  199. c = ' ';
  200. dprintf("%c[%3.3d]", c, i);
  201. PrintfMemLoc(" ", LogMemLoc, " ");
  202. dprintf("%c%c%c%c ", s.c[0], s.c[1], s.c[2], s.c[3]);
  203. PrintfMemLoc(" ", m1, " ");
  204. PrintfMemLoc(" ", m2, " ");
  205. PrintfMemLoc(" ", m3, "\n");
  206. LogMemLoc+=cb;
  207. if (LogMemLoc > EndMemLoc) {
  208. LogMemLoc = StartMemLoc;
  209. }
  210. }
  211. }
  212. DECLARE_API( _eplog )
  213. /*++
  214. Routine Description:
  215. dumps the extension
  216. Arguments:
  217. args - Address flags
  218. Return Value:
  219. None
  220. --*/
  221. {
  222. MEMLOC addr;
  223. PCSTR s;
  224. UCHAR buffer1[256];
  225. UCHAR buffer2[256];
  226. UCHAR buffer3[256];
  227. SIG s1, s2;
  228. ULONG len = 5;
  229. MEMLOC logPtr, logStart, logEnd;
  230. UCHAR cs[] = "_HCD_ENDPOINT";
  231. buffer1[0] = '\0';
  232. buffer2[0] = '\0';
  233. buffer3[0] = '\0';
  234. GetExpressionEx( args, &addr, &s );
  235. PrintfMemLoc("LOG@: ", addr, "\n");
  236. sscanf(s, ",%s %s %s", &buffer1, &buffer2, &buffer3);
  237. if ('\0' != buffer1[0]) {
  238. sscanf(buffer1, "%d", &len);
  239. }
  240. s1.l = 0;
  241. if ('\0' != buffer2[0]) {
  242. // sscanf(buffer2, "%d", &len);
  243. s1.c[0] = buffer2[0];
  244. s1.c[1] = buffer2[1];
  245. s1.c[2] = buffer2[2];
  246. s1.c[3] = buffer2[3];
  247. }
  248. s2.l = 0;
  249. if ('\0' != buffer3[0]) {
  250. // sscanf(buffer2, "%d", &len);
  251. s2.c[0] = buffer3[0];
  252. s2.c[1] = buffer3[1];
  253. s2.c[2] = buffer3[2];
  254. s2.c[3] = buffer3[3];
  255. }
  256. logPtr = UsbReadFieldPtr(addr, cs, "Log.LogPtr");
  257. logStart = UsbReadFieldPtr(addr, cs, "Log.LogStart");
  258. logEnd = UsbReadFieldPtr(addr, cs, "Log.LogEnd");
  259. DumpLog (logPtr,
  260. logStart,
  261. logEnd,
  262. len,
  263. s1.l,
  264. s2.l);
  265. return S_OK;
  266. }
  267. DECLARE_API( _log )
  268. /*++
  269. Routine Description:
  270. dumps the extension
  271. Arguments:
  272. args - Address flags
  273. Return Value:
  274. None
  275. --*/
  276. {
  277. MEMLOC addr;
  278. PCSTR s;
  279. UCHAR buffer1[256];
  280. UCHAR buffer2[256];
  281. UCHAR buffer3[256];
  282. SIG s1, s2;
  283. ULONG len = 5;
  284. MEMLOC logPtr, logStart, logEnd;
  285. UCHAR cs[] = "usbport!_DEVICE_EXTENSION";
  286. ULONG logIdx, m, i;
  287. buffer1[0] = '\0';
  288. buffer2[0] = '\0';
  289. buffer3[0] = '\0';
  290. GetExpressionEx( args, &addr, &s );
  291. PrintfMemLoc("LOG@: ", addr, "\n");
  292. sscanf(s, ",%s %s %s", &buffer1, &buffer2, &buffer3);
  293. if ('\0' != buffer1[0]) {
  294. sscanf(buffer1, "%d", &len);
  295. }
  296. s1.l = 0;
  297. if ('\0' != buffer2[0]) {
  298. // sscanf(buffer2, "%d", &len);
  299. s1.c[0] = buffer2[0];
  300. s1.c[1] = buffer2[1];
  301. s1.c[2] = buffer2[2];
  302. s1.c[3] = buffer2[3];
  303. }
  304. s2.l = 0;
  305. if ('\0' != buffer3[0]) {
  306. // sscanf(buffer2, "%d", &len);
  307. s2.c[0] = buffer3[0];
  308. s2.c[1] = buffer3[1];
  309. s2.c[2] = buffer3[2];
  310. s2.c[3] = buffer3[3];
  311. }
  312. logPtr = UsbReadFieldPtr(addr, cs, "Log.LogStart");
  313. logStart = UsbReadFieldPtr(addr, cs, "Log.LogStart");
  314. logEnd = UsbReadFieldPtr(addr, cs, "Log.LogEnd");
  315. logIdx = UsbReadFieldUlong(addr, cs, "Log.LogIdx");
  316. m = UsbReadFieldUlong(addr, cs, "Log.LogSizeMask");
  317. i = logIdx & m;
  318. dprintf(">LOG mask = %x idx = %x (%x)\n", m, logIdx, i );
  319. if (IsPtr64()) {
  320. logPtr += (i*32);
  321. } else {
  322. logPtr += (i*16);
  323. }
  324. DumpLog (logPtr,
  325. logStart,
  326. logEnd,
  327. len,
  328. s1.l,
  329. s2.l);
  330. return S_OK;
  331. }
  332. DECLARE_API( _xlog )
  333. /*++
  334. Routine Description:
  335. dumps the extension
  336. Arguments:
  337. args - Address flags
  338. Return Value:
  339. None
  340. --*/
  341. {
  342. MEMLOC addr;
  343. PCSTR s;
  344. ULONG len = 5;
  345. UCHAR buffer1[256];
  346. MEMLOC logPtr, logStart, logEnd;
  347. UCHAR cs[] = "usbport!_DEVICE_EXTENSION";
  348. GetExpressionEx( args, &addr, &s );
  349. PrintfMemLoc("LOG@: ", addr, "\n");
  350. sscanf(s, ",%s ", &buffer1);
  351. if ('\0' != buffer1[0]) {
  352. sscanf(buffer1, "%d", &len);
  353. }
  354. logPtr = UsbReadFieldPtr(addr, cs, "TransferLog.LogStart");
  355. logStart = UsbReadFieldPtr(addr, cs, "TransferLog.LogStart");
  356. logEnd = UsbReadFieldPtr(addr, cs, "TransferLog.LogEnd");
  357. DumpXferLog (logPtr,
  358. logStart,
  359. logEnd,
  360. len);
  361. return S_OK;
  362. }
  363. DECLARE_API( _isolog )
  364. /*++
  365. Routine Description:
  366. dumps the extension
  367. Arguments:
  368. args - Address flags
  369. Return Value:
  370. None
  371. --*/
  372. {
  373. MEMLOC addr;
  374. PCSTR s;
  375. UCHAR buffer1[256];
  376. UCHAR buffer2[256];
  377. UCHAR buffer3[256];
  378. SIG s1, s2;
  379. ULONG len = 5;
  380. MEMLOC logPtr, logStart, logEnd;
  381. UCHAR cs[] = "_HCD_ENDPOINT";
  382. buffer1[0] = '\0';
  383. buffer2[0] = '\0';
  384. buffer3[0] = '\0';
  385. GetExpressionEx( args, &addr, &s );
  386. PrintfMemLoc("LOG@: ", addr, "\n");
  387. sscanf(s, ",%s %s %s", &buffer1, &buffer2, &buffer3);
  388. if ('\0' != buffer1[0]) {
  389. sscanf(buffer1, "%d", &len);
  390. }
  391. s1.l = 0;
  392. if ('\0' != buffer2[0]) {
  393. // sscanf(buffer2, "%d", &len);
  394. s1.c[0] = buffer2[0];
  395. s1.c[1] = buffer2[1];
  396. s1.c[2] = buffer2[2];
  397. s1.c[3] = buffer2[3];
  398. }
  399. s2.l = 0;
  400. if ('\0' != buffer3[0]) {
  401. // sscanf(buffer2, "%d", &len);
  402. s2.c[0] = buffer3[0];
  403. s2.c[1] = buffer3[1];
  404. s2.c[2] = buffer3[2];
  405. s2.c[3] = buffer3[3];
  406. }
  407. logPtr = UsbReadFieldPtr(addr, cs, "IsoLog.LogPtr");
  408. logStart = UsbReadFieldPtr(addr, cs, "IsoLog.LogStart");
  409. logEnd = UsbReadFieldPtr(addr, cs, "IsoLog.LogEnd");
  410. DumpLog (logPtr,
  411. logStart,
  412. logEnd,
  413. len,
  414. s1.l,
  415. s2.l);
  416. return S_OK;
  417. }
  418. DECLARE_API( _enumlog )
  419. /*++
  420. Routine Description:
  421. dumps the extension
  422. Arguments:
  423. args - Address flags
  424. Return Value:
  425. None
  426. --*/
  427. {
  428. MEMLOC addr;
  429. PCSTR s;
  430. UCHAR buffer1[256];
  431. UCHAR buffer2[256];
  432. UCHAR buffer3[256];
  433. SIG s1, s2;
  434. ULONG len = 5;
  435. MEMLOC logPtr, logStart, logEnd;
  436. UCHAR csFdo[] = "usbport!_FDO_EXTENSION";
  437. UCHAR cs[] = "usbport!_DEVICE_EXTENSION";
  438. ULONG logIdx, m, i;
  439. buffer1[0] = '\0';
  440. buffer2[0] = '\0';
  441. buffer3[0] = '\0';
  442. GetExpressionEx( args, &addr, &s );
  443. PrintfMemLoc("LOG@: ", addr, "\n");
  444. sscanf(s, ",%s ", &buffer1);
  445. if ('\0' != buffer1[0]) {
  446. sscanf(buffer1, "%d", &len);
  447. }
  448. logPtr = UsbReadFieldPtr(addr, cs, "EnumLog.LogStart");
  449. logStart = UsbReadFieldPtr(addr, cs, "EnumLog.LogStart");
  450. logEnd = UsbReadFieldPtr(addr, cs, "EnumLog.LogEnd");
  451. logIdx = UsbReadFieldUlong(addr, cs, "EnumLog.LogIdx");
  452. m = UsbReadFieldUlong(addr, cs, "EnumLog.LogSizeMask");
  453. i = logIdx & m;
  454. dprintf(">LOG mask = %x idx = %x (%x)\n", m, logIdx, i );
  455. if (IsPtr64()) {
  456. logPtr += (i*32);
  457. } else {
  458. logPtr += (i*16);
  459. }
  460. DumpEnumLog (logPtr,
  461. logStart,
  462. logEnd,
  463. len);
  464. return S_OK;
  465. }