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.

293 lines
7.2 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. devstack.c
  5. Abstract:
  6. WinDbg Extension Api
  7. Author:
  8. Adrian Oney (adriao) 29-Sep-1998
  9. Environment:
  10. User Mode.
  11. Revision History:
  12. --*/
  13. #include "precomp.h"
  14. #pragma hdrstop
  15. /*
  16. #define FLAG_NAME(flag) {flag, #flag}
  17. FLAG_NAME DeviceObjectExtensionFlags[] = {
  18. FLAG_NAME(DOE_UNLOAD_PENDING), // 00000001
  19. FLAG_NAME(DOE_DELETE_PENDING), // 00000002
  20. FLAG_NAME(DOE_REMOVE_PENDING), // 00000004
  21. FLAG_NAME(DOE_REMOVE_PROCESSED), // 00000008
  22. FLAG_NAME(DOE_RAW_FDO), // 20000000
  23. FLAG_NAME(DOE_BOTTOM_OF_FDO_STACK), // 40000000
  24. FLAG_NAME(DOE_DESIGNATED_FDO), // 80000000
  25. { 0, 0 }
  26. };
  27. */
  28. VOID
  29. DumpDeviceStack(
  30. ULONG64 DeviceAddress
  31. );
  32. DECLARE_API( devstack )
  33. /*++
  34. Routine Description:
  35. Dump a device object.
  36. Arguments:
  37. args - the location of the device object to dump.
  38. Return Value:
  39. None
  40. --*/
  41. {
  42. ULONG64 deviceToDump ;
  43. char deviceExprBuf[256] ;
  44. char *deviceExpr ;
  45. //
  46. // !devstack DeviceAddress DumpLevel
  47. // where DeviceAddress can be an expression or device name
  48. // and DumpLevel is a hex mask
  49. //
  50. strcpy(deviceExprBuf, "\\Device\\") ;
  51. deviceExpr = deviceExprBuf+strlen(deviceExprBuf) ;
  52. deviceToDump = 0 ;
  53. if (StringCchCopy(deviceExpr, sizeof(deviceExprBuf) - strlen(deviceExprBuf), args) != S_OK)
  54. {
  55. deviceExpr[0] = 0;
  56. }
  57. //
  58. // sscanf(args, "%255s %lx", deviceExpr, &Flags);
  59. //
  60. //
  61. // The debugger will treat C0000000 as a symbol first, then a number if
  62. // no match comes up. We sanely reverse this ordering.
  63. //
  64. if (IsHexNumber(deviceExpr)) {
  65. deviceToDump = GetExpression (deviceExpr) ;
  66. } else if (deviceExpr[0] == '\\') {
  67. deviceToDump = FindObjectByName( deviceExpr, 0);
  68. } else if (isalpha(deviceExpr[0])) {
  69. //
  70. // Perhaps it's an object. Try with \\Device\\ prepended...
  71. //
  72. deviceToDump = FindObjectByName((PUCHAR) deviceExprBuf, 0);
  73. }
  74. if (deviceToDump == 0) {
  75. //
  76. // Last try, is it an expression to evaluate?
  77. //
  78. deviceToDump = GetExpression( deviceExpr ) ;
  79. }
  80. if(deviceToDump == 0) {
  81. dprintf("Device object %s not found\n", args);
  82. return E_INVALIDARG;
  83. }
  84. DumpDeviceStack(deviceToDump);
  85. return S_OK;
  86. }
  87. VOID
  88. DumpDeviceStack(
  89. ULONG64 DeviceAddress
  90. )
  91. /*++
  92. Routine Description:
  93. Displays the driver name for the device object .
  94. Otherwise displays more information about the device and the device queue.
  95. Arguments:
  96. DeviceAddress - address of device object to dump.
  97. Return Value:
  98. None
  99. --*/
  100. {
  101. ULONG result;
  102. ULONG i;
  103. ULONG64 nextEntry;
  104. BOOLEAN devObjExtRead;
  105. ULONG64 currentDeviceObject ;
  106. ULONG64 DeviceNode=0 ;
  107. ULONG64 AttachedDevice;
  108. ULONG64 DeviceObjectExtension;
  109. ULONG Type;
  110. if (!IsPtr64()) {
  111. DeviceAddress = (ULONG64) (LONG64) (LONG) DeviceAddress;
  112. }
  113. //
  114. // Find top of stack...
  115. //
  116. currentDeviceObject = DeviceAddress;
  117. dprintf(" !DevObj !DrvObj !DevExt ObjectName\n") ;
  118. while(1) {
  119. if (GetFieldValue(currentDeviceObject,"nt!_DEVICE_OBJECT","Type",Type)) {
  120. dprintf("%08p: Could not read device object\n", currentDeviceObject);
  121. return;
  122. }
  123. if (Type != IO_TYPE_DEVICE) {
  124. dprintf("%08p: is not a device object\n", currentDeviceObject);
  125. return;
  126. }
  127. GetFieldValue(currentDeviceObject,"nt!_DEVICE_OBJECT",
  128. "AttachedDevice", AttachedDevice);
  129. if ((!AttachedDevice)||CheckControlC()) {
  130. break;
  131. }
  132. currentDeviceObject = AttachedDevice ;
  133. }
  134. //
  135. // Crawl back down...
  136. //
  137. while(1) {
  138. ULONG64 DeviceExtension, AttachedTo;
  139. InitTypeRead(currentDeviceObject, nt!_DEVICE_OBJECT);
  140. dprintf("%c %08p ",
  141. (currentDeviceObject == DeviceAddress) ? '>' : ' ',
  142. currentDeviceObject
  143. ) ;
  144. DumpDevice(currentDeviceObject, 20, FALSE) ;
  145. InitTypeRead(currentDeviceObject, nt!_DEVICE_OBJECT);
  146. dprintf("%08p ", (DeviceExtension = ReadField(DeviceExtension)));
  147. //
  148. // Dump the device name if present.
  149. //
  150. DumpObjectName(currentDeviceObject) ;
  151. InitTypeRead(currentDeviceObject, nt!_DEVICE_OBJECT);
  152. devObjExtRead = FALSE ;
  153. if (DeviceObjectExtension = ReadField(DeviceObjectExtension)) {
  154. //
  155. // grab a copy of the device object extension as well
  156. //
  157. if(!GetFieldValue(DeviceObjectExtension,"nt!_DEVOBJ_EXTENSION",
  158. "AttachedTo",AttachedTo)) {
  159. devObjExtRead = TRUE ;
  160. }
  161. GetFieldValue(DeviceObjectExtension,"nt!_DEVOBJ_EXTENSION",
  162. "DeviceNode", DeviceNode);
  163. }
  164. if (!devObjExtRead) {
  165. dprintf("\n%#08p: Could not read device object extension\n",
  166. currentDeviceObject);
  167. return ;
  168. }
  169. dprintf("\n");
  170. /*
  171. DumpFlags(0,
  172. "ExtensionFlags",
  173. deviceObjectExtension.ExtensionFlags,
  174. DeviceObjectExtensionFlags);
  175. }
  176. */
  177. currentDeviceObject = AttachedTo ;
  178. if ((!currentDeviceObject)||CheckControlC()) {
  179. break;
  180. }
  181. if (GetFieldValue(currentDeviceObject,"nt!_DEVICE_OBJECT","Type",Type)) {
  182. dprintf("%08p: Could not read device object\n", currentDeviceObject);
  183. return;
  184. }
  185. }
  186. if(DeviceNode) {
  187. UNICODE_STRING64 InstancePath, ServiceName;
  188. dprintf("!DevNode %08p :\n", DeviceNode);
  189. if (GetFieldValue(DeviceNode,
  190. "nt!_DEVICE_NODE",
  191. "InstancePath.Length",
  192. InstancePath.Length)) {
  193. dprintf(
  194. "%08p: Could not read device node\n",
  195. DeviceNode
  196. );
  197. return;
  198. }
  199. InitTypeRead(DeviceNode, nt!_DEVICE_NODE);
  200. InstancePath.MaximumLength = (USHORT) ReadField(InstancePath.MaximumLength);
  201. InstancePath.Buffer = ReadField(InstancePath.Buffer);
  202. ServiceName.Length = (USHORT) ReadField(ServiceName.Length);
  203. ServiceName.MaximumLength = (USHORT) ReadField(ServiceName.MaximumLength);
  204. ServiceName.Buffer = ReadField(ServiceName.Buffer);
  205. if (InstancePath.Buffer != 0) {
  206. dprintf(" DeviceInst is \"");
  207. DumpUnicode64(InstancePath);
  208. dprintf("\"\n");
  209. }
  210. if (ServiceName.Buffer != 0) {
  211. dprintf(" ServiceName is \"");
  212. DumpUnicode64(ServiceName);
  213. dprintf("\"\n");
  214. }
  215. }
  216. }