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.

320 lines
9.4 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995
  5. //
  6. // File: dinfoLevel.cxx
  7. //
  8. // Contents: Display and/or set vaious debug info levels
  9. //
  10. // Functions: infoLevelHelp
  11. // displayInfoLevel
  12. //
  13. //
  14. // History: 06-01-95 BruceMa Created
  15. //
  16. //
  17. //--------------------------------------------------------------------------
  18. #include <ole2int.h>
  19. #include <windows.h>
  20. #include "ole.h"
  21. #include "dinfolvl.h"
  22. #include "debnot.h"
  23. void getArgument(LPSTR *lpArgumentString, LPSTR a);
  24. ULONG ScanAddr(char *lpsz);
  25. static void initInfoLevels(PNTSD_EXTENSION_APIS lpExtensionApis);
  26. static BOOL parseVal(char *arg, ULONG *val);
  27. STable1 debFlags[NUMDEBFLAGS] = {{"error", DEB_ERROR},
  28. {"warn", DEB_WARN},
  29. {"trace", DEB_TRACE},
  30. {"dbgout", DEB_DBGOUT},
  31. {"stdout", DEB_STDOUT},
  32. {"ierror", DEB_IERROR},
  33. {"iwarn", DEB_IWARN},
  34. {"itrace", DEB_ITRACE},
  35. {"user1", DEB_USER1},
  36. {"user2", DEB_USER2},
  37. {"user3", DEB_USER3},
  38. {"user4", DEB_USER4},
  39. {"user5", DEB_USER5},
  40. {"user6", DEB_USER6},
  41. {"user7", DEB_USER7},
  42. {"user8", DEB_USER8},
  43. {"user9", DEB_USER9},
  44. {"user10", DEB_USER10},
  45. {"user11", DEB_USER11},
  46. {"user12", DEB_USER12},
  47. {"user13", DEB_USER13},
  48. {"user14", DEB_USER14},
  49. {"user15", DEB_USER15}};
  50. STable2 infoLevel[NUMINFOLEVELS] = {{"com", NULL, "ole32!_CairoleInfoLevel"},
  51. {"dd", NULL, "ole32!_DDInfoLevel"},
  52. {"hep", NULL, "ole32!_heapInfoLevel"},
  53. {"hk", NULL, "ole32!_hkInfoLevel"},
  54. {"int", NULL, "ole32!_intrInfoLevel"},
  55. {"le", NULL, "ole32!_LEInfoLevel"},
  56. {"mem", NULL, "ole32!_memInfoLevel"},
  57. {"mnk", NULL, "ole32!_mnkInfoLevel"},
  58. {"msf", NULL, "ole32!_msfInfoLevel"},
  59. {"ol", NULL, "ole32!_olInfoLevel"},
  60. {"ref", NULL, "ole32!_RefInfoLevel"},
  61. {"sim", NULL, "ole32!_simpInfoLevel"},
  62. {"stk", NULL, "ole32!_StackInfoLevel"},
  63. {"usr", NULL, "ole32!_UserNdrInfoLevel"}};
  64. //+-------------------------------------------------------------------------
  65. //
  66. // Function: infoLevelHelp
  67. //
  68. // Synopsis: Display a menu for the command 'id'
  69. //
  70. // Arguments: -
  71. //
  72. // Returns: -
  73. //
  74. // History: 07-Mar-95 BruceMa Created
  75. //
  76. //--------------------------------------------------------------------------
  77. void infoLevelHelp(PNTSD_EXTENSION_APIS lpExtensionApis)
  78. {
  79. Printf("in - Display current value of all debug info levels\n");
  80. Printf("in x - Display the current value of debug info level x\n");
  81. Printf("in x y z ... - Set the value of debug info level x to\n");
  82. Printf(" y | z | ... \n");
  83. Printf("\nwhere x corresponds to:\n");
  84. Printf(" --- --------------\n");
  85. Printf(" com ole32!_CairoleInfoLevel\n");
  86. Printf(" dd ole32!_DDInfoLevel\n");
  87. Printf(" hep ole32!_heapInfoLevel\n");
  88. Printf(" hk ole32!_hkInfoLevel\n");
  89. Printf(" int ole32!_intrInfoLevel\n");
  90. Printf(" le ole32!_LEInfoLevel\n");
  91. Printf(" mem ole32!_memInfoLevel\n");
  92. Printf(" mnk ole32!_mnkInfoLevel\n");
  93. Printf(" msf ole32!_msfInfoLevel\n");
  94. Printf(" ol ole32!_olInfoLevel\n");
  95. Printf(" ref ole32!_RefInfoLevel\n");
  96. Printf(" sim ole32!_simpInfoLevel\n");
  97. Printf(" stk ole32!_StackInfoLevel\n");
  98. Printf(" ndr ole32!_UserNdrInfoLevel\n");
  99. Printf("\nand y... corresponds to:\n");
  100. Printf(" ---- --------------\n");
  101. Printf(" error DEB_ERROR\n");
  102. Printf(" warn DEB_WARN\n");
  103. Printf(" trace DEB_TRACE\n");
  104. Printf(" dbgout DEB_DBGOUT\n");
  105. Printf(" stdout DEB_STDOUT\n");
  106. Printf(" ierror DEB_IERROR\n");
  107. Printf(" iwarn DEB_IWARN\n");
  108. Printf(" itrace DEB_ITRACE\n");
  109. Printf(" user1 DEB_USER1\n");
  110. Printf(" user2 DEB_USER2\n");
  111. Printf(" user3 DEB_USER3\n");
  112. Printf(" user4 DEB_USER4\n");
  113. Printf(" user5 DEB_USER5\n");
  114. Printf(" user6 DEB_USER6\n");
  115. Printf(" user7 DEB_USER7\n");
  116. Printf(" user8 DEB_USER8\n");
  117. Printf(" user9 DEB_USER9\n");
  118. Printf(" user10 DEB_USER10\n");
  119. Printf(" user11 DEB_USER11\n");
  120. Printf(" user12 DEB_USER12\n");
  121. Printf(" user13 DEB_USER13\n");
  122. Printf(" user14 DEB_USER14\n");
  123. Printf(" user15 DEB_USER15\n");
  124. Printf(" <hex>\n");
  125. }
  126. //+-------------------------------------------------------------------------
  127. //
  128. // Function: displayInfoLevel
  129. //
  130. // Synopsis: Display/set debug info levels
  131. //
  132. // Arguments: [hProcess] - Handle of this process
  133. // [lpExtensionApis] - Table of extension functions
  134. // [char *] - Command line argument(s)
  135. //
  136. // Returns: -
  137. //
  138. // History: 07-Mar-95 BruceMa Created
  139. //
  140. //--------------------------------------------------------------------------
  141. void displayInfoLevel(HANDLE hProcess,
  142. PNTSD_EXTENSION_APIS lpExtensionApis,
  143. LPSTR lpArgumentString)
  144. {
  145. Arg arg;
  146. UINT k;
  147. ULONG val;
  148. ULONG argVal;
  149. BOOL fSet = FALSE;
  150. // Fetch the addresses for the various debug info levels
  151. initInfoLevels(lpExtensionApis);
  152. // Fetch the first argument
  153. GetArg(arg);
  154. Printf("%s %s\n", arg, lpArgumentString);
  155. // If no argument simply display all info levels
  156. if (!arg[0])
  157. {
  158. for (k = 0; k < NUMINFOLEVELS; k++)
  159. {
  160. ReadMem(&val, infoLevel[k].adr, sizeof(ULONG));
  161. Printf("%s\t%08x\n", infoLevel[k].name, val);
  162. }
  163. return;
  164. }
  165. // Check the info level name
  166. for (k = 0; k < NUMINFOLEVELS; k++)
  167. {
  168. if (lstrcmp(arg, infoLevel[k].name) == 0)
  169. {
  170. break;
  171. }
  172. }
  173. if (k == NUMINFOLEVELS)
  174. {
  175. Printf("...unknown debug info level name\n");
  176. return;
  177. }
  178. // Scan any values to set
  179. val = 0;
  180. for (GetArg(arg); *arg; GetArg(arg))
  181. {
  182. if (!parseVal(arg, &argVal))
  183. {
  184. Printf("...invalid flag expresson\n");
  185. return;
  186. }
  187. val |= argVal;
  188. fSet = TRUE;
  189. }
  190. // If only an info level name, then display its value
  191. if (!fSet)
  192. {
  193. ReadMem(&val, infoLevel[k].adr, sizeof(ULONG));
  194. Printf("%s\t%08x\n", infoLevel[k].name, val);
  195. return;
  196. }
  197. // Otherwise we're setting an info level
  198. WriteMem(infoLevel[k].adr, &val, sizeof(ULONG));
  199. Printf("%s\t%08x\n", infoLevel[k].name, val);
  200. }
  201. //+-------------------------------------------------------------------------
  202. //
  203. // Function: initInfoLevels
  204. //
  205. // Synopsis: Find the addresses of the various infolevels
  206. //
  207. // Arguments: -
  208. //
  209. // Returns: -
  210. //
  211. // History: 07-Mar-95 BruceMa Created
  212. //
  213. //--------------------------------------------------------------------------
  214. static void initInfoLevels(PNTSD_EXTENSION_APIS lpExtensionApis)
  215. {
  216. // Check whether already initialized
  217. if (infoLevel[0].adr != NULL)
  218. {
  219. return;
  220. }
  221. // Do over the info levels
  222. for (UINT k = 0; k < NUMINFOLEVELS; k++)
  223. {
  224. infoLevel[k].adr = GetExpression(infoLevel[k].symbol);
  225. }
  226. }
  227. //+-------------------------------------------------------------------------
  228. //
  229. // Function: parseVal
  230. //
  231. // Synopsis: Parse the next flag expression on the command line
  232. //
  233. // Arguments: [char *] - Command line
  234. // [ULONG *] - Where to return the parsed value
  235. //
  236. // Returns: -
  237. //
  238. // History: 07-Mar-95 BruceMa Created
  239. //
  240. //--------------------------------------------------------------------------
  241. static BOOL parseVal(char *arg, ULONG *val)
  242. {
  243. UINT k;
  244. // Check whether it's a flag name
  245. for (k = 0; k < NUMDEBFLAGS; k++)
  246. {
  247. if (lstrcmp(arg, debFlags[k].name) == 0)
  248. {
  249. *val = debFlags[k].flag;
  250. return TRUE;
  251. }
  252. }
  253. // It's not so it better be hex
  254. k = 0;
  255. if (arg[0] == '0' && arg[1] == 'x')
  256. {
  257. k += 2;
  258. }
  259. while (arg[k])
  260. {
  261. if (!(('0' <= arg[k] && arg[k] <= '9') ||
  262. ('a' <= arg[k] && arg[k] <= 'f')))
  263. {
  264. return FALSE;
  265. }
  266. k++;
  267. }
  268. *val = ScanAddr(arg);
  269. return TRUE;
  270. }