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.

213 lines
4.0 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. devext.c
  5. Abstract:
  6. This file contains the generic routines
  7. for debugging NBF device contexts.
  8. Author:
  9. Chaitanya Kodeboyina
  10. Environment:
  11. User Mode
  12. --*/
  13. #include "precomp.h"
  14. #pragma hdrstop
  15. #include "devext.h"
  16. //
  17. // Exported Functions
  18. //
  19. DECLARE_API( devs )
  20. /*++
  21. Routine Description:
  22. Print a list of devices on the NBF's
  23. devices list [@ nbf!NbfDeviceList ]
  24. Arguments:
  25. args - Detail of debug information
  26. Return Value:
  27. None
  28. --*/
  29. {
  30. DEVICE_CONTEXT DeviceContext;
  31. PLIST_ENTRY NbfDeviceLPtr;
  32. LIST_ENTRY NbfDeviceList;
  33. PLIST_ENTRY p, q;
  34. ULONG proxyPtr;
  35. ULONG numDevs;
  36. ULONG bytesRead;
  37. ULONG printDetail;
  38. // Get the detail of debug information needed
  39. printDetail = SUMM_INFO;
  40. if (*args)
  41. {
  42. sscanf(args, "%lu", &printDetail);
  43. }
  44. // Get the address corresponding to symbol
  45. proxyPtr = GetLocation("nbf!NbfDeviceList");
  46. // Read the list entry of NBF devices
  47. if (!ReadMemory(proxyPtr, &NbfDeviceList, sizeof(LIST_ENTRY), &bytesRead))
  48. {
  49. dprintf("%s @ %08x: Could not read structure\n",
  50. "NbfDeviceList", proxyPtr);
  51. return;
  52. }
  53. // Traverse the doubly linked list
  54. dprintf("Devices:\n");
  55. NbfDeviceLPtr = (PLIST_ENTRY)proxyPtr;
  56. numDevs = 0;
  57. p = NbfDeviceList.Flink;
  58. while (p != NbfDeviceLPtr)
  59. {
  60. // Another Device
  61. numDevs++;
  62. // Device Context Ptr
  63. proxyPtr = (ULONG) CONTAINING_RECORD (p, DEVICE_CONTEXT, Linkage);
  64. // Get Device Context
  65. if (ReadDeviceContext(&DeviceContext, proxyPtr) != 0)
  66. break;
  67. // Print the Context
  68. PrintDeviceContext(&DeviceContext, proxyPtr, printDetail);
  69. // Go to the next one
  70. p = DeviceContext.Linkage.Flink;
  71. // Free Device Context
  72. FreeDeviceContext(&DeviceContext);
  73. }
  74. if (p == NbfDeviceLPtr)
  75. {
  76. dprintf("Number of Devices: %lu\n", numDevs);
  77. }
  78. }
  79. DECLARE_API( dev )
  80. /*++
  81. Routine Description:
  82. Print the device context at an addr
  83. Arguments:
  84. args -
  85. Address of the device context
  86. Detail of debug information
  87. Return Value:
  88. None
  89. --*/
  90. {
  91. DEVICE_CONTEXT DeviceContext;
  92. ULONG printDetail;
  93. ULONG proxyPtr;
  94. // Get the detail of debug information needed
  95. printDetail = NORM_SHAL;
  96. if (*args)
  97. {
  98. sscanf(args, "%x %lu", &proxyPtr, &printDetail);
  99. }
  100. // Get Device Context
  101. if (ReadDeviceContext(&DeviceContext, proxyPtr) != 0)
  102. return;
  103. // Print the Context
  104. PrintDeviceContext(&DeviceContext, proxyPtr, printDetail);
  105. }
  106. //
  107. // Helper Functions
  108. //
  109. UINT
  110. ReadDeviceContext(PDEVICE_CONTEXT pDevCon, ULONG proxyPtr)
  111. {
  112. ULONG bytesRead;
  113. // Read the current device context
  114. if (!ReadMemory(proxyPtr, pDevCon, sizeof(DEVICE_CONTEXT), &bytesRead))
  115. {
  116. dprintf("%s @ %08x: Could not read structure\n",
  117. "DeviceContext", proxyPtr);
  118. return -1;
  119. }
  120. return 0;
  121. }
  122. UINT
  123. PrintDeviceContext(PDEVICE_CONTEXT pDevCon, ULONG proxyPtr, ULONG printDetail)
  124. {
  125. // Is this a valid NBF device context ?
  126. if (pDevCon->Type != NBF_DEVICE_CONTEXT_SIGNATURE)
  127. {
  128. dprintf("%s @ %08x: Could not match signature\n",
  129. "DeviceContext", proxyPtr);
  130. return -1;
  131. }
  132. // What detail do we have to print at ?
  133. if (printDetail > MAX_DETAIL)
  134. printDetail = MAX_DETAIL;
  135. // Print Information at reqd detail
  136. FieldInDeviceContext(proxyPtr, NULL, printDetail);
  137. return 0;
  138. }
  139. VOID
  140. FieldInDeviceContext(ULONG structAddr, CHAR *fieldName, ULONG printDetail)
  141. {
  142. DEVICE_CONTEXT DeviceContext;
  143. if (ReadDeviceContext(&DeviceContext, structAddr) == 0)
  144. {
  145. PrintFields(&DeviceContext, structAddr, fieldName, printDetail, &DeviceContextInfo);
  146. }
  147. }
  148. UINT
  149. FreeDeviceContext(PDEVICE_CONTEXT pDevCon)
  150. {
  151. return 0;
  152. }