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.

321 lines
7.1 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. nbfext.c
  5. Abstract:
  6. This file contains some standard functions
  7. for the NBF kernel debugger extensions dll.
  8. Author:
  9. Chaitanya Kodeboyina (Chaitk)
  10. Environment:
  11. User Mode
  12. --*/
  13. #include "precomp.h"
  14. #pragma hdrstop
  15. #include "nbfext.h"
  16. //
  17. // Globals
  18. //
  19. EXT_API_VERSION ApiVersion = { 5, 0, EXT_API_VERSION_NUMBER, 0 };
  20. WINDBG_EXTENSION_APIS ExtensionApis;
  21. USHORT SavedMajorVersion;
  22. USHORT SavedMinorVersion;
  23. BOOLEAN ChkTarget;
  24. INT Item;
  25. HANDLE _hInstance;
  26. HANDLE _hAdditionalReference;
  27. HANDLE _hProcessHeap;
  28. int _Indent = 0;
  29. char IndentBuf[ 80 ]={"\0 "};
  30. //
  31. // Standard Functions
  32. //
  33. DllInit(
  34. HANDLE hModule,
  35. DWORD dwReason,
  36. DWORD dwReserved
  37. )
  38. {
  39. switch (dwReason)
  40. {
  41. case DLL_THREAD_ATTACH:
  42. break;
  43. case DLL_THREAD_DETACH:
  44. break;
  45. case DLL_PROCESS_DETACH:
  46. break;
  47. case DLL_PROCESS_ATTACH:
  48. _hInstance = hModule;
  49. _hAdditionalReference = NULL;
  50. break;
  51. }
  52. return TRUE;
  53. }
  54. VOID
  55. WinDbgExtensionDllInit(
  56. PWINDBG_EXTENSION_APIS lpExtensionApis,
  57. USHORT MajorVersion,
  58. USHORT MinorVersion
  59. )
  60. {
  61. ExtensionApis = *lpExtensionApis;
  62. SavedMajorVersion = MajorVersion;
  63. SavedMinorVersion = MinorVersion;
  64. ChkTarget = SavedMajorVersion == 0x0c ? TRUE : FALSE;
  65. return;
  66. }
  67. DECLARE_API( version )
  68. {
  69. #if DBG
  70. PCHAR DebuggerType = "Checked";
  71. #else
  72. PCHAR DebuggerType = "Free";
  73. #endif
  74. dprintf( "%s Extension dll for Build %d debugging %s kernel for Build %d\n",
  75. DebuggerType,
  76. VER_PRODUCTBUILD,
  77. SavedMajorVersion == 0x0c ? "Checked" : "Free",
  78. SavedMinorVersion
  79. );
  80. }
  81. VOID
  82. CheckVersion(
  83. VOID
  84. )
  85. {
  86. return;
  87. #if DBG
  88. if ((SavedMajorVersion != 0x0c) || (SavedMinorVersion != VER_PRODUCTBUILD)) {
  89. dprintf("\r\n*** Extension DLL(%d Checked) does not match target system(%d %s)\r\n\r\n",
  90. VER_PRODUCTBUILD, SavedMinorVersion, (SavedMajorVersion==0x0f) ? "Free" : "Checked" );
  91. }
  92. #else
  93. if ((SavedMajorVersion != 0x0f) || (SavedMinorVersion != VER_PRODUCTBUILD)) {
  94. dprintf("\r\n*** Extension DLL(%d Free) does not match target system(%d %s)\r\n\r\n",
  95. VER_PRODUCTBUILD, SavedMinorVersion, (SavedMajorVersion==0x0f) ? "Free" : "Checked" );
  96. }
  97. #endif
  98. }
  99. LPEXT_API_VERSION
  100. ExtensionApiVersion(
  101. VOID
  102. )
  103. {
  104. return &ApiVersion;
  105. }
  106. //
  107. // Exported functions
  108. //
  109. DECLARE_API( help )
  110. /*++
  111. Routine Description:
  112. Command help for NBF debugger extensions.
  113. Arguments:
  114. None
  115. Return Value:
  116. None
  117. --*/
  118. {
  119. dprintf("NBF debugger extension commands:\n\n");
  120. dprintf("\t devs <dbg> - Dump global list of NBF devices\n");
  121. dprintf("\t dev <ptr> <dbg> - Dump an NBF Device Extension\n");
  122. dprintf("\t adrs <ptr> <dbg> - Dump an NBF Address List\n");
  123. dprintf("\t adr <ptr> <dbg> - Dump an NBF Address\n");
  124. dprintf("\t adfs <ptr> <dbg> - Dump an NBF Address File List\n");
  125. dprintf("\t adf <ptr> <dbg> - Dump an NBF Address File\n");
  126. dprintf("\t cons <ptr> <lin> <dbg> - Dump an NBF Connection List\n");
  127. dprintf("\t con <ptr> <dbg> - Dump an NBF Connection\n");
  128. dprintf("\t lnks <ptr> <dbg> - Dump an NBF DLC Link List\n");
  129. dprintf("\t lnk <ptr> <dbg> - Dump an NBF Link\n");
  130. dprintf("\t req <ptr> <dbg> - Dump an NBF Request\n");
  131. dprintf("\t pkt <ptr> <dbg> - Dump an NBF Packet Object\n");
  132. dprintf("\t nhdr <ptr> <dbg> - Dump an NBF Packet Header\n");
  133. /*
  134. dprintf("\t spt <ptr> <dbg> - Dump an NBF Send Packet Tag\n");
  135. dprintf("\t rpt <ptr> <dbg> - Dump an NBF Recv Packet Tag\n");
  136. */
  137. dprintf("\t dlst <ptr> - Dump a d-list from a list entry\n");
  138. dprintf("\t field <struct-code> <struct-addr> <field-prefix> <dbg> \n"
  139. "\t - Dump a field in an NBF structure\n");
  140. dprintf("\n");
  141. dprintf("\t <dbg> - 0 (Validate), 1 (Summary), 2 (Normal Shallow),\n");
  142. dprintf("\t 3(Full Shallow), 4(Normal Deep), 5(Full Deep) \n");
  143. dprintf("\n");
  144. dprintf( "Compiled on " __DATE__ " at " __TIME__ "\n" );
  145. return;
  146. }
  147. DECLARE_API( field )
  148. /**
  149. Routine Description:
  150. Command that print a specified field
  151. in a structure at a particular locn.
  152. Arguments:
  153. args -
  154. Memory location of the structure
  155. Name of the structure
  156. Name of the field
  157. Return Value:
  158. None
  159. --*/
  160. {
  161. CHAR structName[MAX_SYMBOL_LEN];
  162. CHAR fieldName[MAX_SYMBOL_LEN];
  163. ULONG structAddr;
  164. ULONG printDetail;
  165. // Initialize arguments to some defaults
  166. structName[0] = 0;
  167. structAddr = 0;
  168. fieldName[0] = 0;
  169. printDetail = NORM_SHAL;
  170. // Get the arguments and direct control
  171. if (*args)
  172. {
  173. sscanf(args, "%s %x %s %lu", structName, &structAddr, fieldName, &printDetail);
  174. }
  175. if (!_stricmp(structName, "dev"))
  176. {
  177. FieldInDeviceContext(structAddr, fieldName, printDetail);
  178. }
  179. else
  180. if (!_stricmp(structName, "adr"))
  181. {
  182. FieldInAddress(structAddr, fieldName, printDetail);
  183. }
  184. else
  185. if (!_stricmp(structName, "adf"))
  186. {
  187. FieldInAddressFile(structAddr, fieldName, printDetail);
  188. }
  189. else
  190. if (!_stricmp(structName, "con"))
  191. {
  192. FieldInConnection(structAddr, fieldName, printDetail);
  193. }
  194. else
  195. if (!_stricmp(structName, "lnk"))
  196. {
  197. FieldInDlcLink(structAddr, fieldName, printDetail);
  198. }
  199. else
  200. if (!_stricmp(structName, "req"))
  201. {
  202. FieldInRequest(structAddr, fieldName, printDetail);
  203. }
  204. else
  205. if (!_stricmp(structName, "pkt"))
  206. {
  207. FieldInPacket(structAddr, fieldName, printDetail);
  208. }
  209. else
  210. if (!_stricmp(structName, "nhdr"))
  211. {
  212. FieldInNbfPktHdr(structAddr, fieldName, printDetail);
  213. }
  214. /*
  215. if (!_stricmp(structName, "spt"))
  216. {
  217. FieldInSendPacketTag(structAddr, fieldName, printDetail);
  218. }
  219. if (!_stricmp(structName, "rpt"))
  220. {
  221. FieldInRecvPacketTag(structAddr, fieldName, printDetail);
  222. }
  223. */
  224. else
  225. {
  226. dprintf("Unable to understand structure\n");
  227. }
  228. }
  229. DECLARE_API( dlst )
  230. /**
  231. Routine Description:
  232. Print a doubly linked list given list entry
  233. Arguments:
  234. args -
  235. Memory location of the list entry
  236. Offset of the list entry in struct
  237. Return Value:
  238. None
  239. --*/
  240. {
  241. ULONG listHead = 0;
  242. ULONG leOffset = 0;
  243. // Get the arguments and direct control
  244. if (*args)
  245. {
  246. sscanf(args, "%x %x", &listHead, &leOffset);
  247. }
  248. PrintListFromListEntry(NULL, listHead, FULL_DEEP);
  249. }