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.

403 lines
16 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. help.c
  5. Abstract:
  6. Help for AFD.SYS Kernel Debugger Extensions.
  7. Author:
  8. Keith Moore (keithmo) 19-Apr-1995
  9. Environment:
  10. User Mode.
  11. Revision History:
  12. --*/
  13. #include "afdkdp.h"
  14. #pragma hdrstop
  15. //
  16. // Public functions.
  17. //
  18. DECLARE_API( help )
  19. /*++
  20. Routine Description:
  21. Displays help for the AFD.SYS Kernel Debugger Extensions.
  22. Arguments:
  23. None.
  24. Return Value:
  25. None.
  26. --*/
  27. {
  28. gClient = pClient;
  29. dprintf( "? - Displays this list\n" );
  30. dprintf( "help - Displays this list\n" );
  31. dprintf( "endp [-b[rl]|-c|-v] [-r] [-f[co] fld,...] [-s endp | endp... | -e expr]\n"
  32. " - Dumps endpoint(s)\n" );
  33. dprintf( "file [-b[rl]|-v] [file...] [-f[co] fld,...] \n"
  34. " - Dumps endpoint(s) associated with file object(s)\n" );
  35. dprintf( "port [-b[rl]|-c|-v] [-r] [-e expr] [-f[co] fld,...] [-s endp] port\n"
  36. " - Dumps endpoint(s) bound to port(s)\n" );
  37. dprintf( "state [-b[rl]|-c|-v] [-r] [-e expr] [-f[co] fld,...] [-s endp] state\n"
  38. " - Dumps endpoints in specific states\n" );
  39. dprintf( "proc [-b[rl]|-c|-v] [-r] [-e expr] [-f[co] fld,...] [-s endp] [{proc|pid}]\n"
  40. " - Dumps endpoints owned by processes\n" );
  41. dprintf( "conn [-b|-c|-v] [-r] [-f[co] fld,...] [-s endp | conn... | -e expr]\n"
  42. " - Dumps connections\n" );
  43. dprintf( "rport [-b|-c|-v] [-r] [-f[co] fld,...] [-e expr] [-s endp] port\n"
  44. " - Dumps connections to remote ports\n" );
  45. dprintf( "tran [-b[l]|-c|-v] [-r] [-f[co] fld,...] [-s endp | irp... | -e expr]\n"
  46. " - Dumps TransmitPackets/File info\n" );
  47. dprintf( "buff [-b|-c|-v] [-r] [-f[co] fld,...] [-s endp | buff... | -e expr]\n"
  48. " - Dumps buffer structure\n");
  49. dprintf( "poll [-b|-v] [-r] [-f[co] fld,...] [-s endp | poll... | -e expr]\n"
  50. " - Dumps poll info structure(s)\n" );
  51. dprintf( "addr [-b|-v] [-f[co] fld,...] addr\n"
  52. " - Dumps transport address\n" );
  53. dprintf( "addrlist [-b|-v] [-f[co] fld,...] [-e expr]\n"
  54. " - Dumps addresses registered by the transports\n" );
  55. dprintf( "tranlist [-b|-v] [-f[co] fld,...] [-e expr]\n"
  56. " - Dumps transports known to afd (have open sockets)\n" );
  57. dprintf( "filefind <FsContext> - Finds file object given its FsContext field value\n" );
  58. dprintf( "In all of the above:\n" );
  59. dprintf( " -b[rl] - use brief display (1-line per entry),\n"
  60. " r - dump text representation of the remote address,\n"
  61. " l - count items in linked lists (takes time),\n");
  62. dprintf( " -c - don't display entry data, just count them,\n" );
  63. dprintf( " -e expr - while scanning list evaluate the <expr> and only\n"
  64. " dump entry if its result is not 0, prefix <expr> with @@\n"
  65. " to use debugger's C++ evaluator, @$exp represents\n"
  66. " current entry being processed (e.g. @$exp-><FieldName>\n"
  67. " gets field values),\n" );
  68. dprintf( " -f[co] fld,... - dump additional fields of the entries specified\n"
  69. " (comma separated list, no spaces), c-compact,o-no offsets\n" );
  70. dprintf( " -s endp - scan list starting with this endpoint,\n" );
  71. dprintf( " -r - scan endpoint list in reverse order,\n" );
  72. dprintf( " -v - force verbose display,\n" );
  73. dprintf( " endp - AFD_ENDPOINT structure at address <endp>,\n" );
  74. dprintf( " file - FILE_OBJECT structure at address <file>,\n" );
  75. dprintf( " conn - AFD_CONNECTION structure at address <conn>,\n" );
  76. dprintf( " proc - EPROCESS structure at address <proc>,\n" );
  77. dprintf( " pid - process id,\n" );
  78. dprintf( " port - port in host byte order and current debugger base (use n 10|16 to set),\n" );
  79. dprintf( " irp - TPackets/TFile/DisconnectEx IRP at address <irp>,\n" );
  80. dprintf( " buff - AFD_BUFFER_HEADER structure at address <buff>,\n" );
  81. dprintf( " poll - AFD_POLL_INFO_INTERNAL structure at address <poll>,\n" );
  82. dprintf( " addr - TRANSPORT_ADDRESS structure at address <addr>,\n" );
  83. dprintf( " state - endpoint state, valid states are:\n" );
  84. dprintf( " 1 - Open\n" );
  85. dprintf( " 2 - Bound\n" );
  86. dprintf( " 3 - Connected\n" );
  87. dprintf( " 4 - Cleanup\n" );
  88. dprintf( " 5 - Closing\n" );
  89. dprintf( " 6 - TransmitClosing\n" );
  90. dprintf( " 7 - Invalid\n" );
  91. dprintf( " 10 - Listening.\n" );
  92. dprintf( "\n");
  93. if( IsReferenceDebug ) {
  94. dprintf( "cref <conn> - Dumps connection reference debug info\n" );
  95. dprintf( "eref <endp> - Dumps endpoint reference debug info\n" );
  96. dprintf( "tref <tpck> - Dumps tpacket reference debug info\n" );
  97. }
  98. dprintf( "sock [-m] [-f[co] fld,...] [-e expr | Hdl] - Dumps user mode socket context(s)\n"
  99. " for current address space (needs ws2help, ws2_32,\n"
  100. " and %s (for -m) symbols).\n",
  101. SavedMinorVersion>2195 ? "mswsock.dll" : "msafd.dll");
  102. dprintf( "dprov [-f[co] fld,...] [-e expr | prov] - Dumps Winsock2 protocol or catalog\n"
  103. " for current address space (needs ws2_32 symbols).\n");
  104. dprintf( "nprov [-f[co] fld,...] [-e expr | prov] - Dumps Winsock2 namesapce or catalog\n"
  105. " for current address space (needs ws2_32 symbols).\n");
  106. dprintf( "tcb [-w] [-y] [-f[co] fld,...] [-e expr | tcb] - Dumps TCPIP TCB or TCBTable\n"
  107. " -w dumps TWTCBTable, -y dumps SYNTCBTable.\n");
  108. dprintf( "tao [-f[co] fld,...] [-e expr | ao] - Dumps TCPIP AO or AOTable.\n");
  109. dprintf( "tcb6 [-f[co] fld,...] [-e expr | tcb6] - Dumps TCPIP6 TCB or TCBTable.\n");
  110. dprintf( "tao6 [-f[co] fld,...] [-e expr | ao6] - Dumps TCPIP6 AO or AOTable.\n");
  111. dprintf( "stats - Dumps debug-only statistics\n" );
  112. dprintf( "version - Display extension version and reload global info\n" );
  113. #if GLOBAL_REFERENCE_DEBUG
  114. dprintf( "gref - Dumps global reference debug info\n" );
  115. #endif
  116. return S_OK;
  117. } // help
  118. ULONG Options;
  119. ULONG64 StartEndpoint;
  120. CHAR Conditional[MAX_CONDITIONAL_EXPRESSION];
  121. CHAR FieldNames[MAX_FIELDS_EXPRESSION];
  122. FIELD_INFO Fields[MAX_NUM_FIELDS];
  123. SYM_DUMP_PARAM FldParam = {
  124. sizeof (SYM_DUMP_PARAM), // size
  125. NULL, // sName
  126. 0, // Options
  127. 0, // addr
  128. NULL, // listLink
  129. NULL, NULL, // Context,CallbackRoutine
  130. 0, // nFields
  131. Fields // Fields
  132. };
  133. CHAR LinkField[MAX_FIELD_CHARS];
  134. CHAR ListedType[MAX_FIELD_CHARS];
  135. ULONG CppFieldEnd;
  136. PCHAR
  137. ProcessOptions (
  138. IN PCHAR Args
  139. )
  140. {
  141. CHAR expr[max(MAX_FIELDS_EXPRESSION,MAX_CONDITIONAL_EXPRESSION)];
  142. ULONG i;
  143. Options = 0;
  144. CppFieldEnd = 0;
  145. FldParam.nFields = 0;
  146. FldParam.Options = 0;
  147. while (sscanf( Args, "%s%n", expr, &i )==1) {
  148. Args += i;
  149. if (CheckControlC ())
  150. break;
  151. if (expr[0]=='-') {
  152. switch (expr[1]) {
  153. case 'B':
  154. case 'b':
  155. if ((Options & (AFDKD_NO_DISPLAY))==0) {
  156. Options |= AFDKD_BRIEF_DISPLAY;
  157. for (i=2; expr[i]!=0; i++) {
  158. switch (expr[i]) {
  159. case 'l':
  160. Options |= AFDKD_LIST_COUNT;
  161. break;
  162. case 'r':
  163. Options |= AFDKD_RADDR_DISPLAY;
  164. break;
  165. }
  166. }
  167. continue;
  168. }
  169. else {
  170. dprintf ("\nProcessOptions: only one of -b or -c options can be specified.\n");
  171. }
  172. break;
  173. case 'C':
  174. case 'c':
  175. Options |= AFDKD_NO_DISPLAY;
  176. Options &= ~AFDKD_BRIEF_DISPLAY;
  177. continue;
  178. case 'E':
  179. case 'e':
  180. if (sscanf( Args, "%s%n", Conditional, &i )==1) {
  181. Args += i;
  182. Options |= AFDKD_CONDITIONAL;
  183. continue;
  184. }
  185. else {
  186. dprintf ("\nProcessOptions: -e requires an argument.\n");
  187. }
  188. break;
  189. case 'F':
  190. case 'f':
  191. for (i=2; expr[i]!=0; i++) {
  192. switch (expr[i]) {
  193. case 'c':
  194. FldParam.Options |= DBG_DUMP_COMPACT_OUT;
  195. break;
  196. case 'o':
  197. FldParam.Options |= DBG_DUMP_NO_OFFSET;
  198. break;
  199. }
  200. }
  201. if (sscanf( Args, "%s%n", FieldNames, &i )==1) {
  202. PCHAR fld;
  203. Args += i;
  204. Options |= AFDKD_FIELD_DISPLAY;
  205. if (strcmp (FieldNames,".")==0) {
  206. FldParam.nFields = 0;
  207. CppFieldEnd = 0;
  208. continue;
  209. }
  210. for (i=FldParam.nFields, fld = strtok (FieldNames, ",");
  211. i<sizeof (Fields)/sizeof (Fields[0]) && fld!=NULL;
  212. i++, fld = strtok (NULL, ",")) {
  213. Fields[i].fOptions = DBG_DUMP_FIELD_FULL_NAME;
  214. if (*fld=='-') {
  215. fld+=1;
  216. do {
  217. switch (*fld) {
  218. case 'a':
  219. Fields[i].fOptions |= DBG_DUMP_FIELD_ARRAY;
  220. break;
  221. case 'g':
  222. Fields[i].fOptions |= DBG_DUMP_FIELD_GUID_STRING;
  223. break;
  224. case 'm':
  225. Fields[i].fOptions |= DBG_DUMP_FIELD_MULTI_STRING;
  226. break;
  227. case 's':
  228. Fields[i].fOptions |= DBG_DUMP_FIELD_DEFAULT_STRING;
  229. break;
  230. case 'w':
  231. Fields[i].fOptions |= DBG_DUMP_FIELD_WCHAR_STRING;
  232. break;
  233. case 'y':
  234. Fields[i].fOptions &= ~DBG_DUMP_FIELD_FULL_NAME;
  235. break;
  236. }
  237. }
  238. while (*fld++!=':');
  239. }
  240. Fields[i].fName = fld;
  241. }
  242. if (fld==NULL) {
  243. if (i>0) {
  244. FldParam.nFields = i;
  245. CppFieldEnd = i;
  246. for (i=0; i<FldParam.nFields; i++) {
  247. if (strncmp (Fields[i].fName,
  248. AFDKD_CPP_PREFIX,
  249. AFDKD_CPP_PREFSZ)==0) {
  250. FIELD_INFO tmp = Fields[i];
  251. Fields[i] = Fields[--FldParam.nFields];
  252. Fields[FldParam.nFields] = tmp;
  253. }
  254. }
  255. continue;
  256. }
  257. else {
  258. dprintf("\nProcessOptions: -f requires at least one valid field name.\n");
  259. }
  260. }
  261. else {
  262. dprintf("\nProcessOptions: too many fields (>%d) for -f.\n", i);
  263. }
  264. }
  265. else {
  266. dprintf ("\nProcessOptions: -f requires an argument.\n");
  267. }
  268. break;
  269. case 'L':
  270. case 'l':
  271. for (i=2; expr[i]!=0; i++) {
  272. switch (expr[i]) {
  273. case 'a':
  274. Options |= AFDKD_LINK_AOF;
  275. break;
  276. case 's':
  277. Options |= AFDKD_LINK_SELF;
  278. break;
  279. }
  280. }
  281. if (sscanf( Args, "%s%n", LinkField, &i )==1) {
  282. Args += i;
  283. Options |= AFDKD_LINK_FIELD;
  284. continue;
  285. }
  286. else {
  287. dprintf ("\nProcessOptions: -l requires an argument.\n");
  288. }
  289. break;
  290. case 'M':
  291. case 'm':
  292. Options |= AFDKD_MSWSOCK_DISPLAY;
  293. continue;
  294. case 'R':
  295. case 'r':
  296. Options |= AFDKD_BACKWARD_SCAN;
  297. continue;
  298. case 'S':
  299. case 's':
  300. Options |= AFDKD_ENDPOINT_SCAN;
  301. if (sscanf( Args, "%s%n", expr, &i )==1) {
  302. Args += i;
  303. StartEndpoint = GetExpression (expr);
  304. if (StartEndpoint!=0) {
  305. dprintf ("ProcessOptions: StartEndpoint-%p\n", StartEndpoint);
  306. continue;
  307. }
  308. else {
  309. dprintf ("ProcessOptions: StartEndpoint (%s) evaluates to NULL\n", expr);
  310. }
  311. }
  312. else {
  313. dprintf ("\nProcessOptions: %s option missing required parameter.\n", expr);
  314. }
  315. break;
  316. case 'T':
  317. case 't':
  318. if (sscanf( Args, "%s%n", ListedType, &i )==1) {
  319. Args += i;
  320. Options |= AFDKD_LIST_TYPE;
  321. continue;
  322. }
  323. else {
  324. dprintf ("\nProcessOptions: -l requires an argument.\n");
  325. }
  326. break;
  327. case 'V':
  328. case 'v':
  329. Options &= ~AFDKD_BRIEF_DISPLAY;
  330. continue;
  331. case 'W':
  332. case 'w':
  333. if ((Options & (AFDKD_SYNTCB_DISPLAY))==0) {
  334. Options |= AFDKD_TWTCB_DISPLAY;
  335. continue;
  336. }
  337. else {
  338. dprintf ("\nProcessOptions: only one of -y or -w options can be specified.\n");
  339. }
  340. break;
  341. case 'Y':
  342. case 'y':
  343. if ((Options & (AFDKD_TWTCB_DISPLAY))==0) {
  344. Options |= AFDKD_SYNTCB_DISPLAY;
  345. continue;
  346. }
  347. else {
  348. dprintf ("\nProcessOptions: only one of -y or -w options can be specified.\n");
  349. }
  350. break;
  351. default:
  352. dprintf ("\nProcessOptions: Unrecognized option %s.\n", expr);
  353. }
  354. return NULL;
  355. }
  356. else {
  357. Args -= i;
  358. break;
  359. }
  360. }
  361. return Args;
  362. }