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.

4399 lines
118 KiB

  1. /*** amldebug.c - AML Debugger functions
  2. *
  3. * This module contains all the debug functions.
  4. *
  5. * Copyright (c) 1996,1997 Microsoft Corporation
  6. * Author: Michael Tsang (MikeTs)
  7. * Created 08/14/96
  8. *
  9. * MODIFICATION HISTORY
  10. */
  11. #include "pch.h"
  12. #include "unasm.h"
  13. #include <stdio.h>
  14. #include <stdarg.h>
  15. #ifdef DEBUGGER
  16. /*** Local function prototypes
  17. */
  18. LONG LOCAL DebugHelp(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  19. ULONG dwNonSWArgs);
  20. LONG LOCAL DebugExpr(PSZ pszArg, PULONG_PTR puipValue, BOOLEAN *pfPhysical,
  21. PPNSOBJ ppns, PULONG pdwOffset);
  22. BOOLEAN LOCAL IsNumber(PSZ pszStr, ULONG dwBase, PULONG_PTR puipValue);
  23. LONG LOCAL AddBrkPt(PUCHAR pbBrkPt);
  24. LONG LOCAL ClearBrkPt(int iBrkPt);
  25. LONG LOCAL SetBrkPtState(int iBrkPt, BOOLEAN fEnable);
  26. LONG LOCAL EnableDisableBP(PSZ pszArg, BOOLEAN fEnable);
  27. LONG LOCAL DebugBC(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum, ULONG dwNonSWArgs);
  28. LONG LOCAL DebugBD(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum, ULONG dwNonSWArgs);
  29. LONG LOCAL DebugBE(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum, ULONG dwNonSWArgs);
  30. LONG LOCAL DebugBL(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum, ULONG dwNonSWArgs);
  31. LONG LOCAL DebugBP(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum, ULONG dwNonSWArgs);
  32. LONG LOCAL DebugClearLog(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  33. ULONG dwNonSWArgs);
  34. LONG LOCAL DumpData(ULONG_PTR uipAddr, ULONG dwfUnitSize, ULONG dwLen,
  35. BOOLEAN fPhysical);
  36. LONG LOCAL DebugDumpData(PCMDARG pArg, PSZ pszArg, ULONG dwfDataSize);
  37. LONG LOCAL DebugD(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum, ULONG dwNonSWArgs);
  38. LONG LOCAL DebugDB(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum, ULONG dwNonSWArgs);
  39. LONG LOCAL DebugDW(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum, ULONG dwNonSWArgs);
  40. LONG LOCAL DebugDD(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum, ULONG dwNonSWArgs);
  41. LONG LOCAL DebugDA(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum, ULONG dwNonSWArgs);
  42. #ifdef DEBUG
  43. LONG LOCAL DebugDC(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum, ULONG dwNonSWArgs);
  44. LONG LOCAL DebugDumpHeap(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  45. ULONG dwNonSWArgs);
  46. VOID LOCAL DumpHeap(PHEAP pheap);
  47. #endif
  48. LONG LOCAL DebugDumpLog(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  49. ULONG dwNonSWArgs);
  50. LONG LOCAL DebugDumpStack(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  51. ULONG dwNonSWArgs);
  52. VOID LOCAL DumpStack(PCTXT pctxt, BOOLEAN fVerbose);
  53. LONG LOCAL DebugDumpNameSpace(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  54. ULONG dwNonSWArgs);
  55. LONG LOCAL DebugDumpObject(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  56. ULONG dwNonSWArgs);
  57. LONG LOCAL DebugEditMem(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  58. ULONG dwNonSWArgs);
  59. LONG LOCAL DebugFindNSObj(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  60. ULONG dwNonSWArgs);
  61. BOOLEAN LOCAL FindNSObj(NAMESEG dwName, PNSOBJ pnsRoot);
  62. LONG LOCAL InPort(ULONG dwPort, ULONG dwSize, PULONG pdwData);
  63. LONG LOCAL DebugInPort(PSZ pszArg, ULONG dwSize);
  64. LONG LOCAL DebugI(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum, ULONG dwNonSWArgs);
  65. LONG LOCAL DebugIW(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum, ULONG dwNonSWArgs);
  66. LONG LOCAL DebugID(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum, ULONG dwNonSWArgs);
  67. LONG LOCAL DebugQuit(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  68. ULONG dwNonSWArgs);
  69. LONG LOCAL DebugListCtxts(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  70. ULONG dwNonSWArgs);
  71. LONG LOCAL DebugLN(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum, ULONG dwNonSWArgs);
  72. LONG LOCAL DebugNotify(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  73. ULONG dwNonSWArgs);
  74. LONG LOCAL OutPort(ULONG dwPort, ULONG dwSize, ULONG dwData);
  75. LONG LOCAL DebugOutPort(PSZ pszArg, ULONG dwSize);
  76. LONG LOCAL DebugO(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum, ULONG dwNonSWArgs);
  77. LONG LOCAL DebugOW(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum, ULONG dwNonSWArgs);
  78. LONG LOCAL DebugOD(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum, ULONG dwNonSWArgs);
  79. VOID LOCAL PrintSymbol(PUCHAR pb);
  80. LONG LOCAL DebugTrace(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  81. ULONG dwNonSWArgs);
  82. LONG LOCAL DebugStep(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  83. ULONG dwNonSWArgs);
  84. VOID LOCAL DumpContext(PCTXT pctxt);
  85. LONG LOCAL DebugDumpContext(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  86. ULONG dwNonSWArgs);
  87. LONG LOCAL DebugSet(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  88. ULONG dwNonSWArgs);
  89. LONG LOCAL DebugSetLogSize(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  90. ULONG dwNonSWArgs);
  91. LONG LOCAL DebugUnAsm(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  92. ULONG dwNonSWArgs);
  93. LONG LOCAL DebugRunMethod(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  94. ULONG dwNonSWArgs);
  95. VOID EXPORT RunMethodCallBack(PNSOBJ pns, NTSTATUS rc, POBJDATA pdata,
  96. PVOID pvContext);
  97. VOID LOCAL AddObjSymbol(PUCHAR pbOp, PNSOBJ pnsObj);
  98. BOOLEAN LOCAL FindObjSymbol(PUCHAR pbOp, PPNSOBJ ppns, PULONG pdwOffset);
  99. /*** Exported data
  100. */
  101. DBGR gDebugger = {0};
  102. /*** Local data
  103. */
  104. ULONG dwCmdArg = 0;
  105. CMDARG ArgsHelp[] =
  106. {
  107. NULL, AT_ACTION, 0, NULL, 0, DebugHelp,
  108. NULL, AT_END, 0, NULL, 0, NULL
  109. };
  110. CMDARG ArgsBC[] =
  111. {
  112. NULL, AT_ACTION, 0, NULL, 0, DebugBC,
  113. NULL, AT_END, 0, NULL, 0, NULL
  114. };
  115. CMDARG ArgsBD[] =
  116. {
  117. NULL, AT_ACTION, 0, NULL, 0, DebugBD,
  118. NULL, AT_END, 0, NULL, 0, NULL
  119. };
  120. CMDARG ArgsBE[] =
  121. {
  122. NULL, AT_ACTION, 0, NULL, 0, DebugBE,
  123. NULL, AT_END, 0, NULL, 0, NULL
  124. };
  125. CMDARG ArgsBP[] =
  126. {
  127. NULL, AT_ACTION, 0, NULL, 0, DebugBP,
  128. NULL, AT_END, 0, NULL, 0, NULL
  129. };
  130. CMDARG ArgsD[] =
  131. {
  132. "l", AT_NUM, AF_SEP, &dwCmdArg, 16, DebugD,
  133. NULL, AT_ACTION, 0, NULL, 0, DebugD,
  134. NULL, AT_END, 0, NULL, 0, NULL
  135. };
  136. CMDARG ArgsDB[] =
  137. {
  138. "l", AT_NUM, AF_SEP, &dwCmdArg, 16, DebugDB,
  139. NULL, AT_ACTION, 0, NULL, 0, DebugDB,
  140. NULL, AT_END, 0, NULL, 0, NULL
  141. };
  142. CMDARG ArgsDW[] =
  143. {
  144. "l", AT_NUM, AF_SEP, &dwCmdArg, 16, DebugDW,
  145. NULL, AT_ACTION, 0, NULL, 0, DebugDW,
  146. NULL, AT_END, 0, NULL, 0, NULL
  147. };
  148. CMDARG ArgsDD[] =
  149. {
  150. "l", AT_NUM, AF_SEP, &dwCmdArg, 16, DebugDD,
  151. NULL, AT_ACTION, 0, NULL, 0, DebugDD,
  152. NULL, AT_END, 0, NULL, 0, NULL
  153. };
  154. CMDARG ArgsDA[] =
  155. {
  156. "l", AT_NUM, AF_SEP, &dwCmdArg, 16, DebugDA,
  157. NULL, AT_ACTION, 0, NULL, 0, DebugDA,
  158. NULL, AT_END, 0, NULL, 0, NULL
  159. };
  160. #ifdef DEBUG
  161. CMDARG ArgsDumpHeap[] =
  162. {
  163. NULL, AT_ACTION, 0, NULL, 0, DebugDumpHeap,
  164. NULL, AT_END, 0, NULL, 0, NULL
  165. };
  166. #endif
  167. CMDARG ArgsDumpStack[] =
  168. {
  169. #ifdef DEBUG
  170. "v", AT_ENABLE, 0, &dwCmdArg, DSF_VERBOSE, NULL,
  171. #endif
  172. NULL, AT_ACTION, 0, NULL, 0, DebugDumpStack,
  173. NULL, AT_END, 0, NULL, 0, NULL
  174. };
  175. CMDARG ArgsDNS[] =
  176. {
  177. "s", AT_ENABLE, 0, &dwCmdArg, DNSF_RECURSE, NULL,
  178. NULL, AT_ACTION, 0, NULL, 0, DebugDumpNameSpace,
  179. NULL, AT_END, 0, NULL, 0, NULL
  180. };
  181. CMDARG ArgsDumpObject[] =
  182. {
  183. NULL, AT_ACTION, 0, NULL, 0, DebugDumpObject,
  184. NULL, AT_END, 0, NULL, 0, NULL
  185. };
  186. CMDARG ArgsEditMem[] =
  187. {
  188. NULL, AT_ACTION, 0, NULL, 0, DebugEditMem,
  189. NULL, AT_END, 0, NULL, 0, NULL
  190. };
  191. CMDARG ArgsFindNS[] =
  192. {
  193. NULL, AT_ACTION, 0, NULL, 0, DebugFindNSObj,
  194. NULL, AT_END, 0, NULL, 0, NULL
  195. };
  196. CMDARG ArgsI[] =
  197. {
  198. NULL, AT_NUM, 0, &dwCmdArg, 16, DebugI,
  199. NULL, AT_END, 0, NULL, 0, NULL
  200. };
  201. CMDARG ArgsIW[] =
  202. {
  203. NULL, AT_NUM, 0, &dwCmdArg, 16, DebugIW,
  204. NULL, AT_END, 0, NULL, 0, NULL
  205. };
  206. CMDARG ArgsID[] =
  207. {
  208. NULL, AT_NUM, 0, &dwCmdArg, 16, DebugID,
  209. NULL, AT_END, 0, NULL, 0, NULL
  210. };
  211. CMDARG ArgsLN[] =
  212. {
  213. NULL, AT_ACTION, 0, NULL, 0, DebugLN,
  214. NULL, AT_END, 0, NULL, 0, NULL
  215. };
  216. CMDARG ArgsNotify[] =
  217. {
  218. NULL, AT_ACTION, 0, NULL, 0, DebugNotify,
  219. NULL, AT_END, 0, NULL, 0, NULL
  220. };
  221. CMDARG ArgsO[] =
  222. {
  223. NULL, AT_NUM, 0, &dwCmdArg, 16, DebugO,
  224. NULL, AT_END, 0, NULL, 0, NULL
  225. };
  226. CMDARG ArgsOW[] =
  227. {
  228. NULL, AT_NUM, 0, &dwCmdArg, 16, DebugOW,
  229. NULL, AT_END, 0, NULL, 0, NULL
  230. };
  231. CMDARG ArgsOD[] =
  232. {
  233. NULL, AT_NUM, 0, &dwCmdArg, 16, DebugOD,
  234. NULL, AT_END, 0, NULL, 0, NULL
  235. };
  236. CMDARG ArgsDumpCtxt[] =
  237. {
  238. NULL, AT_ACTION, 0, NULL, 0, DebugDumpContext,
  239. NULL, AT_END, 0, NULL, 0, NULL
  240. };
  241. CMDARG ArgsRunMethod[] =
  242. {
  243. NULL, AT_ACTION, 0, NULL, 0, DebugRunMethod,
  244. NULL, AT_END, 0, NULL, 0, NULL
  245. };
  246. CMDARG ArgsSetOptions[] =
  247. {
  248. "traceon", AT_ENABLE, 0, &gDebugger.dwfDebugger, DBGF_AMLTRACE_ON, NULL,
  249. "traceoff", AT_DISABLE, 0, &gDebugger.dwfDebugger, DBGF_AMLTRACE_ON, NULL,
  250. "spewon", AT_ENABLE, 0, &gDebugger.dwfDebugger, DBGF_DEBUG_SPEW_ON, NULL,
  251. "spewoff", AT_DISABLE, 0, &gDebugger.dwfDebugger, DBGF_DEBUG_SPEW_ON, NULL,
  252. "nesttraceon", AT_DISABLE, 0, &gDebugger.dwfDebugger, DBGF_TRACE_NONEST, NULL,
  253. "nesttraceoff", AT_ENABLE, 0, &gDebugger.dwfDebugger, DBGF_TRACE_NONEST, NULL,
  254. "lbrkon", AT_ENABLE, 0, &gdwfAMLIInit, AMLIIF_LOADDDB_BREAK, NULL,
  255. "lbrkoff", AT_DISABLE, 0, &gdwfAMLIInit, AMLIIF_LOADDDB_BREAK, NULL,
  256. "errbrkon", AT_ENABLE, 0, &gDebugger.dwfDebugger, DBGF_ERRBREAK_ON, NULL,
  257. "errbrkoff", AT_DISABLE, 0, &gDebugger.dwfDebugger, DBGF_ERRBREAK_ON, NULL,
  258. "verboseon", AT_ENABLE, 0, &gDebugger.dwfDebugger, DBGF_VERBOSE_ON, NULL,
  259. "verboseoff", AT_DISABLE, 0, &gDebugger.dwfDebugger, DBGF_VERBOSE_ON, NULL,
  260. "logon", AT_ENABLE, 0, &gDebugger.dwfDebugger, DBGF_LOGEVENT_ON, NULL,
  261. "logoff", AT_DISABLE, 0, &gDebugger.dwfDebugger, DBGF_LOGEVENT_ON, NULL,
  262. "logmuton", AT_ENABLE, 0, &gDebugger.dwfDebugger, DBGF_LOGEVENT_MUTEX, NULL,
  263. "logmutoff", AT_DISABLE, 0, &gDebugger.dwfDebugger, DBGF_LOGEVENT_MUTEX, NULL,
  264. "logsize", AT_NUM, AF_SEP, &dwCmdArg, 10, DebugSetLogSize,
  265. NULL, AT_END, 0, NULL, 0, NULL
  266. };
  267. #ifdef TRACING
  268. CMDARG ArgsSetTrace[] =
  269. {
  270. "trigon", AT_ENABLE, 0, &gDebugger.dwfDebugger, DBGF_TRIGGER_MODE, NULL,
  271. "trigoff", AT_DISABLE, 0, &gDebugger.dwfDebugger, DBGF_TRIGGER_MODE, NULL,
  272. "level", AT_NUM, AF_SEP, &giTraceLevel, 0, NULL,
  273. "add", AT_STRING, AF_SEP, &gpszTrigPts, 0, AddTraceTrigPts,
  274. "zap", AT_STRING, AF_SEP, &gpszTrigPts, 0, ZapTraceTrigPts,
  275. NULL, AT_END, 0, NULL, 0, NULL
  276. };
  277. #endif
  278. CMDARG ArgsUnAsm[] =
  279. {
  280. NULL, AT_ACTION, 0, NULL, 0, DebugUnAsm,
  281. NULL, AT_END, 0, NULL, 0, NULL
  282. };
  283. DBGCMD DbgCmds[] =
  284. {
  285. "?", 0, ArgsHelp, DebugHelp,
  286. "bc", 0, ArgsBC, DebugBC,
  287. "bd", 0, ArgsBD, DebugBD,
  288. "be", 0, ArgsBE, DebugBE,
  289. "bl", 0, NULL, DebugBL,
  290. "bp", 0, ArgsBP, DebugBP,
  291. "cl", 0, NULL, DebugClearLog,
  292. "d", 0, ArgsD, DebugD,
  293. "db", 0, ArgsDB, DebugDB,
  294. "dw", 0, ArgsDW, DebugDW,
  295. "dd", 0, ArgsDD, DebugDD,
  296. "da", 0, ArgsDA, DebugDA,
  297. #ifdef DEBUG
  298. "dc", 0, NULL, DebugDC,
  299. "dh", 0, ArgsDumpHeap, DebugDumpHeap,
  300. #endif
  301. "dl", 0, NULL, DebugDumpLog,
  302. "ds", 0, ArgsDumpStack, DebugDumpStack,
  303. "dns", 0, ArgsDNS, DebugDumpNameSpace,
  304. "do", 0, ArgsDumpObject, DebugDumpObject,
  305. "e", 0, ArgsEditMem, DebugEditMem,
  306. "find", 0, ArgsFindNS, DebugFindNSObj,
  307. "g", CMDF_QUIT, NULL, NULL,
  308. "i", 0, ArgsI, DebugI,
  309. "iw", 0, ArgsIW, DebugIW,
  310. "id", 0, ArgsID, DebugID,
  311. "lc", 0, NULL, DebugListCtxts,
  312. "ln", 0, ArgsLN, DebugLN,
  313. "notify", 0, ArgsNotify, DebugNotify,
  314. "o", 0, ArgsO, DebugO,
  315. "ow", 0, ArgsOW, DebugOW,
  316. "od", 0, ArgsOD, DebugOD,
  317. "p", 0, NULL, DebugStep,
  318. "q", 0, NULL, DebugQuit,
  319. "r", 0, ArgsDumpCtxt, DebugDumpContext,
  320. "run", 0, ArgsRunMethod, DebugRunMethod,
  321. "set", 0, ArgsSetOptions, DebugSet,
  322. "t", 0, NULL, DebugTrace,
  323. #ifdef TRACING
  324. "trace", 0, ArgsSetTrace, SetTrace,
  325. #endif
  326. "u", 0, ArgsUnAsm, DebugUnAsm,
  327. NULL, 0, NULL, NULL
  328. };
  329. /***EP AMLIDebugger - AMLI Debugger
  330. *
  331. * ENTRY
  332. * fCallFromVxD - debugger is invoked by the VxD .. command.
  333. *
  334. * EXIT
  335. * None
  336. */
  337. VOID STDCALL AMLIDebugger(BOOLEAN fCallFromVxD)
  338. {
  339. if (!(gDebugger.dwfDebugger & DBGF_IN_KDSHELL))
  340. {
  341. if (fCallFromVxD)
  342. {
  343. gDebugger.dwfDebugger |= DBGF_IN_VXDMODE;
  344. }
  345. else
  346. {
  347. gDebugger.dwfDebugger &= ~DBGF_IN_VXDMODE;
  348. }
  349. gDebugger.dwfDebugger |= DBGF_IN_DEBUGGER;
  350. Debugger(DbgCmds, "\n" MODNAME "(? for help)-> ");
  351. gDebugger.dwfDebugger &= ~(DBGF_IN_DEBUGGER | DBGF_IN_VXDMODE);
  352. }
  353. else
  354. {
  355. PRINTF("\nRe-entering AML debugger is not allowed.\n"
  356. "Type 'g' to go back to the AML debugger.\n");
  357. }
  358. } //AMLIDebugger
  359. /***LP DebugHelp - help
  360. *
  361. * ENTRY
  362. * pArg -> argument type entry
  363. * pszArg -> argument string
  364. * dwArgNum - argument number
  365. * dwNonSWArgs - number of non-switch arguments
  366. *
  367. * EXIT-SUCCESS
  368. * returns DBGERR_NONE
  369. * EXIT-FAILURE
  370. * returns negative error code
  371. */
  372. LONG LOCAL DebugHelp(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  373. ULONG dwNonSWArgs)
  374. {
  375. LONG rc = DBGERR_NONE;
  376. DEREF(pArg);
  377. DEREF(dwNonSWArgs);
  378. //
  379. // User typed ? <cmd>
  380. //
  381. if (pszArg != NULL)
  382. {
  383. if (STRCMP(pszArg, "?") == 0)
  384. {
  385. PRINTF("\nHelp:\n");
  386. PRINTF("Usage: ? [<Cmd>]\n");
  387. PRINTF("<Cmd> - command to get help on\n");
  388. }
  389. else if (STRCMP(pszArg, "bc") == 0)
  390. {
  391. PRINTF("\nClear Breakpoints:\n");
  392. PRINTF("Usage: bc <bp list> | *\n");
  393. PRINTF("<bp list> - list of breakpoint numbers\n");
  394. PRINTF("* - all breakpoints\n");
  395. }
  396. else if (STRCMP(pszArg, "bd") == 0)
  397. {
  398. PRINTF("\nDisable Breakpoints:\n");
  399. PRINTF("Usage: bd <bp list> | *\n");
  400. PRINTF("<bp list> - list of breakpoint numbers\n");
  401. PRINTF("* - all breakpoints\n");
  402. }
  403. else if (STRCMP(pszArg, "be") == 0)
  404. {
  405. PRINTF("\nEnable Breakpoints:\n");
  406. PRINTF("Usage: be <bp list> | *\n");
  407. PRINTF("<bp list> - list of breakpoint numbers\n");
  408. PRINTF("* - all breakpoints\n");
  409. }
  410. else if (STRCMP(pszArg, "bl") == 0)
  411. {
  412. PRINTF("\nList All Breakpoints:\n");
  413. PRINTF("Usage: bl\n");
  414. }
  415. else if (STRCMP(pszArg, "bp") == 0)
  416. {
  417. PRINTF("\nSet BreakPoints:\n");
  418. PRINTF("Usage: bp <MethodName> | <CodeAddr> ...\n");
  419. PRINTF("<MethodName> - full path of method name to have breakpoint set at\n");
  420. PRINTF("<CodeAddr> - address of AML code to have breakpoint set at\n");
  421. }
  422. else if (STRCMP(pszArg, "cl") == 0)
  423. {
  424. PRINTF("\nClear Event Log:\n");
  425. PRINTF("Usage: cl\n");
  426. }
  427. else if (STRCMP(pszArg, "d") == 0)
  428. {
  429. PRINTF("\nDump Data:\n");
  430. PRINTF("Usage: d [[l=<Len>] <Addr> | <MethodName>]\n");
  431. PRINTF("<Len> - length of address range in hex\n");
  432. PRINTF("<Addr> - data address (physical address if prefixed by \"%%\")\n");
  433. PRINTF("<MethodName> - full path of method name\n");
  434. }
  435. else if (STRCMP(pszArg, "db") == 0)
  436. {
  437. PRINTF("\nDump Data Bytes:\n");
  438. PRINTF("Usage: db [[l=<Len>] <Addr> | <MethodName>]\n");
  439. PRINTF("<Len> - length of address range in hex\n");
  440. PRINTF("<Addr> - data address (physical address if prefixed by \"%%\")\n");
  441. PRINTF("<MethodName> - full path of method name\n");
  442. }
  443. else if (STRCMP(pszArg, "dw") == 0)
  444. {
  445. PRINTF("\nDump Data Words:\n");
  446. PRINTF("Usage: dw [[l=<Len>] <Addr> | <MethodName>]\n");
  447. PRINTF("<Len> - length of address range in hex\n");
  448. PRINTF("<Addr> - data address (physical address if prefixed by \"%%\")\n");
  449. PRINTF("<MethodName> - full path of method name\n");
  450. }
  451. else if (STRCMP(pszArg, "dd") == 0)
  452. {
  453. PRINTF("\nDump Data DWords:\n");
  454. PRINTF("Usage: dd [[l=<Len>] <Addr> | <MethodName>]\n");
  455. PRINTF("<Len> - length of address rangein hex\n");
  456. PRINTF("<Addr> - data address (physical address if prefixed by \"%%\")\n");
  457. PRINTF("<MethodName> - full path of method name\n");
  458. }
  459. else if (STRCMP(pszArg, "da") == 0)
  460. {
  461. PRINTF("\nDump Data String:\n");
  462. PRINTF("Usage: da [[l=<Len>] <Addr> | <MethodName>]\n");
  463. PRINTF("<Len> - length of address range in hex\n");
  464. PRINTF("<Addr> - data address (physical address if prefixed by \"%%\")\n");
  465. PRINTF("<MethodName> - full path of method name\n");
  466. }
  467. #ifdef DEBUG
  468. else if (STRCMP(pszArg, "dc") == 0)
  469. {
  470. PRINTF("\nDump Memory Object Count Table:\n");
  471. PRINTF("Usage: dc\n");
  472. }
  473. else if (STRCMP(pszArg, "dh") == 0)
  474. {
  475. PRINTF("\nDump Heap:\n");
  476. PRINTF("Usage: dh [<Addr>]\n");
  477. PRINTF("<Addr> - address of the heap block, global heap if missing\n");
  478. }
  479. #endif
  480. else if (STRCMP(pszArg, "dl") == 0)
  481. {
  482. PRINTF("\nDump Event Log:\n");
  483. PRINTF("Usage: dl\n");
  484. }
  485. else if (STRCMP(pszArg, "ds") == 0)
  486. {
  487. PRINTF("\nDump Stack:\n");
  488. #ifdef DEBUG
  489. PRINTF("Usage: ds [/v] [<Addr>]\n");
  490. PRINTF("v - enable versbos mode\n");
  491. #else
  492. PRINTF("Usage: ds [<Addr>]\n");
  493. #endif
  494. PRINTF("<Addr> - address of the context block, use current context if missing\n");
  495. }
  496. else if (STRCMP(pszArg, "dns") == 0)
  497. {
  498. PRINTF("\nDump Name Space Object:\n");
  499. PRINTF("Usage: dns [[/s] [<NameStr> | <Addr>]]\n");
  500. PRINTF("s - recursively dump the name space subtree\n");
  501. PRINTF("<NameStr> - name space path (dump whole name space if absent)\n");
  502. PRINTF("<Addr> - specify address of the name space object\n");
  503. }
  504. else if (STRCMP(pszArg, "do") == 0)
  505. {
  506. PRINTF("\nDump Data Object:\n");
  507. PRINTF("Usage: do <Addr>\n");
  508. PRINTF("<Addr> - address of the data object\n");
  509. }
  510. else if (STRCMP(pszArg, "e") == 0)
  511. {
  512. PRINTF("\nEdit Memory:\n");
  513. PRINTF("Usage: e [<Addr> [<DataList>]]\n");
  514. PRINTF("<Addr> - memory address (physical address if prefixed by \"%%\")\n");
  515. PRINTF("<DataList> - list of data separated by spaces, "
  516. "data can be a byte or a string\n");
  517. }
  518. else if (STRCMP(pszArg, "find") == 0)
  519. {
  520. PRINTF("\nFind NameSpace Object:\n");
  521. PRINTF("Usage: find <NameSeg>\n");
  522. PRINTF("<NameSeg> - Name of the NameSpace object without path\n");
  523. }
  524. else if (STRCMP(pszArg, "g") == 0)
  525. {
  526. PRINTF("\nQuit debugger, continue normal execution.\n");
  527. }
  528. else if (STRCMP(pszArg, "i") == 0)
  529. {
  530. PRINTF("\nRead Data From a Byte Port:\n");
  531. PRINTF("Usage: i <Port>\n");
  532. PRINTF("<Port> - port address\n");
  533. }
  534. else if (STRCMP(pszArg, "iw") == 0)
  535. {
  536. PRINTF("\nRead Data From a Word Port:\n");
  537. PRINTF("Usage: iw <Port>\n");
  538. PRINTF("<Port> - port address\n");
  539. }
  540. else if (STRCMP(pszArg, "id") == 0)
  541. {
  542. PRINTF("\nRead Data From a DWord Port:\n");
  543. PRINTF("Usage: id <Port>\n");
  544. PRINTF("<Port> - port address\n");
  545. }
  546. else if (STRCMP(pszArg, "lc") == 0)
  547. {
  548. PRINTF("\nList All Contexts:\n");
  549. PRINTF("Usage: lc\n");
  550. }
  551. else if (STRCMP(pszArg, "ln") == 0)
  552. {
  553. PRINTF("\nDisplay Nearest Method Name:\n");
  554. PRINTF("Usage: ln [<MethodName> | <CodeAddr>]\n");
  555. PRINTF("<MethodName> - full path of method name\n");
  556. PRINTF("<CodeAddr> - address of AML code\n");
  557. }
  558. else if (STRCMP(pszArg, "notify") == 0)
  559. {
  560. PRINTF("\nNotify a NameSpace Object:\n");
  561. PRINTF("Usage: notify <Obj> <Value>\n");
  562. PRINTF("<Obj> - full NameSpace path of object or its address\n");
  563. PRINTF("<Value> - notification value\n");
  564. }
  565. else if (STRCMP(pszArg, "o") == 0)
  566. {
  567. PRINTF("\nWrite Data to a Byte Port:\n");
  568. PRINTF("Usage: o <Port> <Byte>\n");
  569. PRINTF("<Port> - port address\n");
  570. PRINTF("<Byte> - data to be written\n");
  571. }
  572. else if (STRCMP(pszArg, "ow") == 0)
  573. {
  574. PRINTF("\nWrite Data to a Word Port:\n");
  575. PRINTF("Usage: ow <Port> <Word>\n");
  576. PRINTF("<Port> - port address\n");
  577. PRINTF("<Word> - data to be written\n");
  578. }
  579. else if (STRCMP(pszArg, "od") == 0)
  580. {
  581. PRINTF("\nWrite Data to a DWord Port:\n");
  582. PRINTF("Usage: o <Port> <DWord>\n");
  583. PRINTF("<Port> - port address\n");
  584. PRINTF("<DWord> - data to be written\n");
  585. }
  586. else if (STRCMP(pszArg, "p") == 0)
  587. {
  588. PRINTF("\nStep over AML Code\n");
  589. PRINTF("Usage: p\n");
  590. }
  591. else if (STRCMP(pszArg, "q") == 0)
  592. {
  593. PRINTF("\nQuit to kernel debugger:\n");
  594. PRINTF("Usage: q\n");
  595. }
  596. else if (STRCMP(pszArg, "r") == 0)
  597. {
  598. PRINTF("\nDisplay Context Information:\n");
  599. PRINTF("Usage: r\n");
  600. }
  601. else if (STRCMP(pszArg, "run") == 0)
  602. {
  603. PRINTF("\nRun a Method:\n");
  604. PRINTF("Usage: run <MethodName> | <CodeAddr> [<ArgList>]\n");
  605. PRINTF("<MethodName> - full path of method name\n");
  606. PRINTF("<CodeAddr> - address of method\n");
  607. PRINTF("<ArgList> - list of integer arguments\n");
  608. }
  609. else if (STRCMP(pszArg, "set") == 0)
  610. {
  611. PRINTF("\nSet Debugger Options:\n");
  612. PRINTF("Usage: set [traceon | traceoff] [nesttraceon | nesttraceoff] [spewon | spewoff]\n"
  613. " [lbrkon | lbrkoff] [errbrkon | errbrkoff] [verboseon | verboseoff]\n"
  614. " [logon | logoff] [logmuton | logmutoff] [logsize=<MaxNumEvents>]\n");
  615. PRINTF("traceon - turn on AML tracing\n");
  616. PRINTF("traceoff - turn off AML tracing\n");
  617. PRINTF("nesttraceon - turn on nest tracing (only valid with traceon)\n");
  618. PRINTF("nesttraceoff - turn off nest tracing (only valid with traceon)\n");
  619. PRINTF("spewon - turn on debug spew\n");
  620. PRINTF("spewoff - turn off debug spew\n");
  621. PRINTF("lbrkon - enable load DDB completion break\n");
  622. PRINTF("lbrkoff - disable load DDB completion break\n");
  623. PRINTF("errbrkon - enable break on error\n");
  624. PRINTF("errbrkoff - disable break on error\n");
  625. PRINTF("verboseon - enable verbose mode\n");
  626. PRINTF("verboseoff - disable verbose mode\n");
  627. PRINTF("logon - enable event logging\n");
  628. PRINTF("logoff - disable event logging\n");
  629. PRINTF("logmuton - enable mutex event logging\n");
  630. PRINTF("logmutoff - disable mutex event logging\n");
  631. PRINTF("logsize - set event log size (default 128)\n");
  632. }
  633. else if (STRCMP(pszArg, "t") == 0)
  634. {
  635. PRINTF("\nTrace Into AML Code:\n");
  636. PRINTF("Usage: t\n");
  637. }
  638. #ifdef TRACING
  639. else if (STRCMP(pszArg, "trace") == 0)
  640. {
  641. PRINTF("\nInterpreter Trace Mode:\n");
  642. PRINTF("Usage: trace [trigon] [trigoff] [level=<n>] [add=<TrigPtStr>] [zap=<TrigPtList>]\n");
  643. PRINTF("trigon - turn on trace trigger mode\n");
  644. PRINTF("trigoff - turn off trace trigger mode\n");
  645. PRINTF("level - set trace level to <n>\n");
  646. PRINTF("add - add trace trigger points\n");
  647. PRINTF("<TrigPtStr> - list of trigger point strings separated by commas\n");
  648. PRINTF("zap - zap trace trigger points\n");
  649. PRINTF("<TrigPtList> - list of trigger point numbers separated by commas\n");
  650. }
  651. #endif
  652. else if (STRCMP(pszArg, "u") == 0)
  653. {
  654. PRINTF("\nUnassemble AML code:\n");
  655. PRINTF("Usage: u [<MethodName> | <CodeAddr>]\n");
  656. PRINTF("<MethodName> - full path of method name\n");
  657. PRINTF("<CodeAddr> - address of AML code\n");
  658. }
  659. else
  660. {
  661. DBG_ERROR(("invalid help command - %s", pszArg));
  662. rc = DBGERR_INVALID_CMD;
  663. }
  664. }
  665. //
  666. // User typed just a "?" without any arguments
  667. //
  668. else if (dwArgNum == 0)
  669. {
  670. PRINTF("\n");
  671. PRINTF("Help - ? [<Cmd>]\n");
  672. PRINTF("Clear Breakpoints - bc <bp list> | *\n");
  673. PRINTF("Disable Breakpoints - bd <bp list> | *\n");
  674. PRINTF("Enable Breakpoints - be <bp list> | *\n");
  675. PRINTF("List Breakpoints - bl\n");
  676. PRINTF("Set Breakpoints - bp <MethodName> | <CodeAddr> ...\n");
  677. PRINTF("Clear Event Log - cl\n");
  678. PRINTF("Dump Data - d [[l=<Len>] <Addr>]\n");
  679. PRINTF("Dump Data Bytes - db [[l=<Len>] <Addr>]\n");
  680. PRINTF("Dump Data Words - dw [[l=<Len>] <Addr>]\n");
  681. PRINTF("Dump Data DWords - dd [[l=<Len>] <Addr>]\n");
  682. PRINTF("Dump Data String - da [[l=<Len>] <Addr>]\n");
  683. PRINTF("Dump Event Log - dl\n");
  684. #ifdef DEBUG
  685. PRINTF("Dump Object Count Table - dc\n");
  686. PRINTF("Dump Heap - dh [<Addr>]\n");
  687. PRINTF("Dump Stack - ds [/v] [<Addr>]\n");
  688. #else
  689. PRINTF("Dump Stack - ds [<Addr>]\n");
  690. #endif
  691. PRINTF("Dump Name Space Object - dns [[/s] [<NameStr> | <Addr>]]\n");
  692. PRINTF("Dump Data Object - do <Addr>\n");
  693. PRINTF("Edit Memory - e [<Addr> [<DataList>]]\n");
  694. PRINTF("Find NameSpace Object - find <NameSeg>\n");
  695. PRINTF("Continue Execution - g\n");
  696. PRINTF("Read Byte from Port - i <Port>\n");
  697. PRINTF("Read Word from Port - iw <Port>\n");
  698. PRINTF("Read DWord from Port - id <Port>\n");
  699. PRINTF("List All Contexts - lc\n");
  700. PRINTF("Display Nearest Method - ln [<MethodName> | <CodeAddr>]\n");
  701. PRINTF("Notify NameSpace Object - notify <Obj> <Value>\n");
  702. PRINTF("Write Byte to Port - o <Port> <Byte>\n");
  703. PRINTF("Write Word to Port - ow <Port> <Word>\n");
  704. PRINTF("Write DWord to Port - od <Port> <DWord>\n");
  705. PRINTF("Step Over AML Code - p\n");
  706. PRINTF("Quit to Kernel Debugger - q\n");
  707. PRINTF("Display Context Info. - r\n");
  708. PRINTF("Run Method - run <MethodName> | <CodeAddr> [<ArgList>]\n");
  709. PRINTF("Set Debugger Options - set [traceon | traceoff] [nesttraceon | nesttraceoff]\n"
  710. " [spewon | spewoff] [lbrkon | lbrkoff] \n"
  711. " [errbrkon | errbrkoff] [verboseon | verboseoff] \n"
  712. " [logon | logoff] [logmuton | logmutoff] \n"
  713. " [logsize=<MaxNumEvents>]\n");
  714. PRINTF("Trace Into AML Code - t\n");
  715. #ifdef TRACING
  716. PRINTF("Interpreter Trace Mode - trace [trigon] [trigoff] [level=<n>]\n"
  717. " [add=<TrigPtStr] [zap=<TrigPtList>]\n");
  718. #endif
  719. PRINTF("Unassemble AML code - u [<MethodName> | <CodeAddr>]\n");
  720. }
  721. return rc;
  722. } //DebugHelp
  723. /***LP DebugExpr - Parse debugger expression
  724. *
  725. * ENTRY
  726. * pszArg -> expression argument
  727. * puipValue -> to hold the result of expression
  728. * pfPhysical -> set to TRUE if the expression is a physical address
  729. * (NULL if don't allow physical address)
  730. * ppns -> to hold the pointer of the nearest pns object
  731. * pdwOffset -> to hold the offset of the address to the nearest pns object
  732. *
  733. * EXIT-SUCCESS
  734. * returns DBGERR_NONE
  735. * EXIT-FAILURE
  736. * returns DBGERR_CMD_FAILED
  737. */
  738. LONG LOCAL DebugExpr(PSZ pszArg, PULONG_PTR puipValue, BOOLEAN *pfPhysical,
  739. PPNSOBJ ppns, PULONG pdwOffset)
  740. {
  741. LONG rc = DBGERR_NONE;
  742. PNSOBJ pns = NULL;
  743. ULONG dwOffset = 0;
  744. if (pfPhysical != NULL)
  745. *pfPhysical = FALSE;
  746. if ((pfPhysical != NULL) && (pszArg[0] == '%') && (pszArg[1] == '%'))
  747. {
  748. if (IsNumber(&pszArg[2], 16, puipValue))
  749. {
  750. *pfPhysical = TRUE;
  751. }
  752. else
  753. {
  754. DBG_ERROR(("invalid physical address - %s", pszArg));
  755. rc = DBGERR_INVALID_CMD;
  756. }
  757. }
  758. else if (!IsNumber(pszArg, 16, puipValue))
  759. {
  760. STRUPR(pszArg);
  761. if ((GetNameSpaceObject(pszArg, NULL, &pns, NSF_LOCAL_SCOPE) ==
  762. STATUS_SUCCESS) &&
  763. (pns->ObjData.dwDataType == OBJTYPE_METHOD))
  764. {
  765. *puipValue = (ULONG_PTR)
  766. (((PMETHODOBJ)pns->ObjData.pbDataBuff)->abCodeBuff);
  767. }
  768. else
  769. {
  770. DBG_ERROR(("object not found or object is not a method - %s",
  771. pszArg));
  772. rc = DBGERR_INVALID_CMD;
  773. }
  774. }
  775. else if (FindObjSymbol((PUCHAR)*puipValue, &pns, &dwOffset))
  776. {
  777. if ((pns->ObjData.dwDataType != OBJTYPE_METHOD) ||
  778. (dwOffset >= pns->ObjData.dwDataLen -
  779. FIELD_OFFSET(METHODOBJ, abCodeBuff)))
  780. {
  781. pns = NULL;
  782. dwOffset = 0;
  783. }
  784. }
  785. if (rc == DBGERR_NONE)
  786. {
  787. if (ppns != NULL)
  788. *ppns = pns;
  789. if (pdwOffset != NULL)
  790. *pdwOffset = dwOffset;
  791. }
  792. return rc;
  793. } //DebugExpr
  794. /***LP IsNumber - Check if string is a number, if so return the number
  795. *
  796. * ENTRY
  797. * pszStr -> string
  798. * dwBase - base
  799. * puipValue -> to hold the number
  800. *
  801. * EXIT-SUCCESS
  802. * returns TRUE - the string is a number
  803. * EXIT-FAILURE
  804. * returns FALSE - the string is not a number
  805. */
  806. BOOLEAN LOCAL IsNumber(PSZ pszStr, ULONG dwBase, PULONG_PTR puipValue)
  807. {
  808. BOOLEAN rc;
  809. PSZ psz;
  810. *puipValue = (ULONG_PTR)STRTOUL(pszStr, &psz, dwBase);
  811. if ((psz != pszStr) && (*psz == '\0'))
  812. rc = TRUE;
  813. else
  814. rc = FALSE;
  815. return rc;
  816. } //IsNumber
  817. /***LP AddBrkPt - Add breakpoint
  818. *
  819. * ENTRY
  820. * pbBrkPt - breakpoint
  821. *
  822. * EXIT-SUCCESS
  823. * returns DBGERR_NONE
  824. * EXIT-FAILURE
  825. * returns DBGERR_CMD_FAILED
  826. */
  827. LONG LOCAL AddBrkPt(PUCHAR pbBrkPt)
  828. {
  829. LONG rc = DBGERR_NONE;
  830. int i, iBrkPt;
  831. for (i = 0, iBrkPt = -1; i < MAX_BRK_PTS; ++i)
  832. {
  833. if ((pbBrkPt == gDebugger.BrkPts[i].pbBrkPt) ||
  834. (iBrkPt == -1) && (gDebugger.BrkPts[i].pbBrkPt == NULL))
  835. {
  836. iBrkPt = i;
  837. }
  838. }
  839. if (iBrkPt == -1)
  840. {
  841. DBG_ERROR(("no free breakpoint"));
  842. rc = DBGERR_CMD_FAILED;
  843. }
  844. else if (gDebugger.BrkPts[iBrkPt].pbBrkPt == NULL)
  845. {
  846. gDebugger.BrkPts[iBrkPt].pbBrkPt = pbBrkPt;
  847. gDebugger.BrkPts[iBrkPt].dwfBrkPt = BPF_ENABLED;
  848. }
  849. return rc;
  850. } //AddBrkPt
  851. /***LP ClearBrkPt - Clear breakpoint
  852. *
  853. * ENTRY
  854. * iBrkPt - breakpoint number
  855. *
  856. * EXIT-SUCCESS
  857. * returns DBGERR_NONE
  858. * EXIT-FAILURE
  859. * returns DBGERR_CMD_FAILED
  860. */
  861. LONG LOCAL ClearBrkPt(int iBrkPt)
  862. {
  863. LONG rc;
  864. if (iBrkPt < MAX_BRK_PTS)
  865. {
  866. MEMZERO(&gDebugger.BrkPts[iBrkPt], sizeof(BRKPT));
  867. rc = DBGERR_NONE;
  868. }
  869. else
  870. {
  871. DBG_ERROR(("invalid breakpoint number"));
  872. rc = DBGERR_CMD_FAILED;
  873. }
  874. return rc;
  875. } //ClearBrkPt
  876. /***LP SetBrkPtState - Enable/Disable breakpoint
  877. *
  878. * ENTRY
  879. * iBrkPt - breakpoint number
  880. * fEnable - enable breakpoint
  881. *
  882. * EXIT-SUCCESS
  883. * returns DBGERR_NONE
  884. * EXIT-FAILURE
  885. * returns DBGERR_CMD_FAILED
  886. */
  887. LONG LOCAL SetBrkPtState(int iBrkPt, BOOLEAN fEnable)
  888. {
  889. LONG rc;
  890. if (iBrkPt < MAX_BRK_PTS)
  891. {
  892. if (gDebugger.BrkPts[iBrkPt].pbBrkPt != NULL)
  893. {
  894. if (fEnable)
  895. gDebugger.BrkPts[iBrkPt].dwfBrkPt |= BPF_ENABLED;
  896. else
  897. gDebugger.BrkPts[iBrkPt].dwfBrkPt &= ~BPF_ENABLED;
  898. }
  899. rc = DBGERR_NONE;
  900. }
  901. else
  902. {
  903. DBG_ERROR(("invalid breakpoint number"));
  904. rc = DBGERR_CMD_FAILED;
  905. }
  906. return rc;
  907. } //SetBrkPtState
  908. /***LP EnableDisableBP - Enable/Disable BreakPoints
  909. *
  910. * ENTRY
  911. * pszArg -> argument string
  912. * fEnable - TRUE if enable breakpoints
  913. *
  914. * EXIT-SUCCESS
  915. * returns DBGERR_NONE
  916. * EXIT-FAILURE
  917. * returns negative error code
  918. */
  919. LONG LOCAL EnableDisableBP(PSZ pszArg, BOOLEAN fEnable)
  920. {
  921. LONG rc = DBGERR_NONE;
  922. static BOOLEAN fProcessed = FALSE;
  923. if (pszArg != NULL)
  924. {
  925. ULONG dwBrkPt;
  926. if (STRCMP(pszArg, "*") == 0)
  927. {
  928. for (dwBrkPt = 0; dwBrkPt < MAX_BRK_PTS; ++dwBrkPt)
  929. {
  930. if ((rc = SetBrkPtState((int)dwBrkPt, fEnable)) != DBGERR_NONE)
  931. break;
  932. }
  933. }
  934. else if (IsNumber(pszArg, 10, (PULONG_PTR)&dwBrkPt))
  935. {
  936. rc = SetBrkPtState((int)dwBrkPt, fEnable);
  937. }
  938. else
  939. {
  940. DBG_ERROR(("invalid breakpoint number"));
  941. rc = DBGERR_INVALID_CMD;
  942. }
  943. if (rc == DBGERR_NONE)
  944. fProcessed = TRUE;
  945. }
  946. else
  947. {
  948. if (fProcessed)
  949. fProcessed = FALSE;
  950. else
  951. {
  952. DBG_ERROR(("invalid breakpoint command"));
  953. rc = DBGERR_INVALID_CMD;
  954. }
  955. }
  956. return rc;
  957. } //EnableDisableBP
  958. /***LP DebugBC - Clear BreakPoint
  959. *
  960. * ENTRY
  961. * pArg -> argument type entry
  962. * pszArg -> argument string
  963. * dwArgNum - argument number
  964. * dwNonSWArgs - number of non-switch arguments
  965. *
  966. * EXIT-SUCCESS
  967. * returns DBGERR_NONE
  968. * EXIT-FAILURE
  969. * returns negative error code
  970. */
  971. LONG LOCAL DebugBC(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum, ULONG dwNonSWArgs)
  972. {
  973. LONG rc = DBGERR_NONE;
  974. static BOOLEAN fProcessed = FALSE;
  975. DEREF(pArg);
  976. DEREF(dwArgNum);
  977. DEREF(dwNonSWArgs);
  978. if (pszArg != NULL)
  979. {
  980. ULONG dwBrkPt;
  981. if (STRCMP(pszArg, "*") == 0)
  982. {
  983. for (dwBrkPt = 0; dwBrkPt < MAX_BRK_PTS; ++dwBrkPt)
  984. {
  985. if ((rc = ClearBrkPt((int)dwBrkPt)) != DBGERR_NONE)
  986. break;
  987. }
  988. }
  989. else if (IsNumber(pszArg, 10, (PULONG_PTR)&dwBrkPt))
  990. {
  991. rc = ClearBrkPt((int)dwBrkPt);
  992. }
  993. else
  994. {
  995. DBG_ERROR(("invalid breakpoint number"));
  996. rc = DBGERR_INVALID_CMD;
  997. }
  998. if (rc == DBGERR_NONE)
  999. fProcessed = TRUE;
  1000. }
  1001. else
  1002. {
  1003. if (fProcessed)
  1004. fProcessed = FALSE;
  1005. else
  1006. {
  1007. DBG_ERROR(("invalid breakpoint command"));
  1008. rc = DBGERR_INVALID_CMD;
  1009. }
  1010. }
  1011. return rc;
  1012. } //DebugBC
  1013. /***LP DebugBD - Disable BreakPoint
  1014. *
  1015. * ENTRY
  1016. * pArg -> argument type entry
  1017. * pszArg -> argument string
  1018. * dwArgNum - argument number
  1019. * dwNonSWArgs - number of non-switch arguments
  1020. *
  1021. * EXIT-SUCCESS
  1022. * returns DBGERR_NONE
  1023. * EXIT-FAILURE
  1024. * returns negative error code
  1025. */
  1026. LONG LOCAL DebugBD(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum, ULONG dwNonSWArgs)
  1027. {
  1028. LONG rc;
  1029. DEREF(pArg);
  1030. DEREF(dwArgNum);
  1031. DEREF(dwNonSWArgs);
  1032. rc = EnableDisableBP(pszArg, FALSE);
  1033. return rc;
  1034. } //DebugBD
  1035. /***LP DebugBE - Enable BreakPoint
  1036. *
  1037. * ENTRY
  1038. * pArg -> argument type entry
  1039. * pszArg -> argument string
  1040. * dwArgNum - argument number
  1041. * dwNonSWArgs - number of non-switch arguments
  1042. *
  1043. * EXIT-SUCCESS
  1044. * returns DBGERR_NONE
  1045. * EXIT-FAILURE
  1046. * returns negative error code
  1047. */
  1048. LONG LOCAL DebugBE(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum, ULONG dwNonSWArgs)
  1049. {
  1050. LONG rc;
  1051. DEREF(pArg);
  1052. DEREF(dwArgNum);
  1053. DEREF(dwNonSWArgs);
  1054. rc = EnableDisableBP(pszArg, TRUE);
  1055. return rc;
  1056. } //DebugBE
  1057. /***LP DebugBL - List BreakPoints
  1058. *
  1059. * ENTRY
  1060. * pArg -> argument type entry
  1061. * pszArg -> argument string
  1062. * dwArgNum - argument number
  1063. * dwNonSWArgs - number of non-switch arguments
  1064. *
  1065. * EXIT-SUCCESS
  1066. * returns DBGERR_NONE
  1067. * EXIT-FAILURE
  1068. * returns negative error code
  1069. */
  1070. LONG LOCAL DebugBL(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum, ULONG dwNonSWArgs)
  1071. {
  1072. LONG rc;
  1073. DEREF(pArg);
  1074. DEREF(dwArgNum);
  1075. DEREF(dwNonSWArgs);
  1076. if (pszArg == NULL)
  1077. {
  1078. int i;
  1079. PNSOBJ pns;
  1080. ULONG dwOffset;
  1081. for (i = 0; i < MAX_BRK_PTS; ++i)
  1082. {
  1083. if (gDebugger.BrkPts[i].pbBrkPt != NULL)
  1084. {
  1085. PRINTF("%2d: <%c> %08x",
  1086. i,
  1087. (gDebugger.BrkPts[i].dwfBrkPt & BPF_ENABLED)? 'e': 'd',
  1088. gDebugger.BrkPts[i].pbBrkPt);
  1089. if (FindObjSymbol(gDebugger.BrkPts[i].pbBrkPt, &pns, &dwOffset))
  1090. {
  1091. PRINTF(" [%s", GetObjectPath(pns));
  1092. if (dwOffset != 0)
  1093. {
  1094. PRINTF(" + %x]\n", dwOffset);
  1095. }
  1096. else
  1097. {
  1098. PRINTF("]\n");
  1099. }
  1100. }
  1101. else
  1102. {
  1103. PRINTF("\n");
  1104. }
  1105. }
  1106. }
  1107. rc = DBGERR_NONE;
  1108. }
  1109. else
  1110. {
  1111. DBG_ERROR(("invalid breakpoint command"));
  1112. rc = DBGERR_INVALID_CMD;
  1113. }
  1114. return rc;
  1115. } //DebugBL
  1116. /***LP DebugBP - Set BreakPoint
  1117. *
  1118. * ENTRY
  1119. * pArg -> argument type entry
  1120. * pszArg -> argument string
  1121. * dwArgNum - argument number
  1122. * dwNonSWArgs - number of non-switch arguments
  1123. *
  1124. * EXIT-SUCCESS
  1125. * returns DBGERR_NONE
  1126. * EXIT-FAILURE
  1127. * returns negative error code
  1128. */
  1129. LONG LOCAL DebugBP(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum, ULONG dwNonSWArgs)
  1130. {
  1131. LONG rc = DBGERR_NONE;
  1132. static BOOLEAN fProcessed = FALSE;
  1133. DEREF(pArg);
  1134. DEREF(dwArgNum);
  1135. DEREF(dwNonSWArgs);
  1136. if (pszArg != NULL)
  1137. {
  1138. PUCHAR pbBrkPt;
  1139. if ((rc = DebugExpr(pszArg, (PULONG_PTR)&pbBrkPt, NULL, NULL, NULL)) ==
  1140. DBGERR_NONE)
  1141. {
  1142. rc = AddBrkPt(pbBrkPt);
  1143. }
  1144. if (rc == DBGERR_NONE)
  1145. fProcessed = TRUE;
  1146. }
  1147. else
  1148. {
  1149. if (fProcessed)
  1150. fProcessed = FALSE;
  1151. else
  1152. {
  1153. DBG_ERROR(("invalid breakpoint command"));
  1154. rc = DBGERR_INVALID_CMD;
  1155. }
  1156. }
  1157. return rc;
  1158. } //DebugBP
  1159. /***LP DebugClearLog - Clear event log
  1160. *
  1161. * ENTRY
  1162. * pArg -> argument type entry
  1163. * pszArg -> argument string
  1164. * dwArgNum - argument number
  1165. * dwNonSWArgs - number of non-switch arguments
  1166. *
  1167. * EXIT-SUCCESS
  1168. * returns DBGERR_NONE
  1169. * EXIT-FAILURE
  1170. * returns negative error code
  1171. */
  1172. LONG LOCAL DebugClearLog(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  1173. ULONG dwNonSWArgs)
  1174. {
  1175. LONG rc;
  1176. DEREF(pArg);
  1177. DEREF(dwArgNum);
  1178. DEREF(dwNonSWArgs);
  1179. if (pszArg == NULL)
  1180. {
  1181. if (gDebugger.pEventLog != NULL)
  1182. {
  1183. MEMZERO(gDebugger.pEventLog, sizeof(EVENTLOG)*gDebugger.dwLogSize);
  1184. gDebugger.dwLogIndex = 0;
  1185. rc = DBGERR_NONE;
  1186. }
  1187. else
  1188. {
  1189. DBG_ERROR(("no event log allocated"));
  1190. rc = DBGERR_CMD_FAILED;
  1191. }
  1192. }
  1193. else
  1194. {
  1195. DBG_ERROR(("invalid CL command"));
  1196. rc = DBGERR_INVALID_CMD;
  1197. }
  1198. return rc;
  1199. } //DebugClearLog
  1200. /***LP DumpData - Dump data
  1201. *
  1202. * ENTRY
  1203. * uipAddr - data address
  1204. * dwfUnitSize - DBGF_DUMPDATA_MASK flags
  1205. * dwLen - length of data range
  1206. * fPhysical - TRUE if uipAddr is a physical address
  1207. *
  1208. * EXIT-SUCCESS
  1209. * returns DBGERR_NONE
  1210. * EXIT-FAILURE
  1211. * returns negative error code
  1212. */
  1213. LONG LOCAL DumpData(ULONG_PTR uipAddr, ULONG dwfUnitSize, ULONG dwLen,
  1214. BOOLEAN fPhysical)
  1215. {
  1216. LONG rc = DBGERR_NONE;
  1217. PUCHAR pbData = NULL;
  1218. PSZ pszPrefix = "";
  1219. gDebugger.dwfDebugger &= ~(DBGF_DUMPDATA_MASK | DBGF_DUMPDATA_PHYADDR);
  1220. gDebugger.dwfDebugger |= dwfUnitSize;
  1221. if (fPhysical)
  1222. {
  1223. gDebugger.dwfDebugger |= DBGF_DUMPDATA_PHYADDR;
  1224. pszPrefix = "%%";
  1225. if (MapUnmapPhysMem(NULL, uipAddr, dwLen, (PULONG_PTR)&pbData) !=
  1226. STATUS_SUCCESS)
  1227. {
  1228. DBG_ERROR(("Failed to map physical address %x", uipAddr));
  1229. rc = DBGERR_CMD_FAILED;
  1230. }
  1231. }
  1232. else
  1233. pbData = (PUCHAR)uipAddr;
  1234. if (ASSERTRANGE(pbData, dwLen))
  1235. {
  1236. if (dwfUnitSize == DBGF_DUMPDATA_STRING)
  1237. {
  1238. gDebugger.uipDumpDataAddr = uipAddr;
  1239. PRINTF("%s%08x: ", pszPrefix, uipAddr);
  1240. while ((dwLen > 0) && (*pbData != '\0'))
  1241. {
  1242. PRINTF("%c",
  1243. ((*pbData >= ' ') && (*pbData <= '~'))? *pbData: '.');
  1244. pbData++;
  1245. dwLen--;
  1246. }
  1247. PRINTF("\n");
  1248. }
  1249. else
  1250. {
  1251. PUCHAR pbEnd = pbData + dwLen;
  1252. ULONG dwDataSize = DATASIZE(dwfUnitSize);
  1253. int i;
  1254. for (i = 0; pbData < pbEnd;)
  1255. {
  1256. if (i == 0)
  1257. PRINTF("%s%08x: ", pszPrefix, uipAddr);
  1258. else if ((i == 8) && (dwDataSize == sizeof(UCHAR)))
  1259. PRINTF("-");
  1260. else
  1261. PRINTF(" ");
  1262. switch (dwDataSize)
  1263. {
  1264. case sizeof(UCHAR):
  1265. PRINTF("%02x", *pbData);
  1266. break;
  1267. case sizeof(USHORT):
  1268. PRINTF("%04x", *((PUSHORT)pbData));
  1269. break;
  1270. case sizeof(ULONG):
  1271. PRINTF("%08x", *((PULONG)pbData));
  1272. }
  1273. pbData += dwDataSize;
  1274. uipAddr += (ULONG_PTR)dwDataSize;
  1275. i += (int)dwDataSize;
  1276. if (i == 0x10)
  1277. {
  1278. if (dwDataSize == sizeof(UCHAR))
  1279. {
  1280. UCHAR b;
  1281. PRINTF(" ");
  1282. for (i = 0x10; i > 0; --i)
  1283. {
  1284. b = *(pbData - i);
  1285. PRINTF("%c", ((b >= ' ') && (b <= '~'))? b: '.');
  1286. }
  1287. }
  1288. i = 0;
  1289. PRINTF("\n");
  1290. }
  1291. }
  1292. gDebugger.uipDumpDataAddr = uipAddr;
  1293. }
  1294. }
  1295. else
  1296. {
  1297. DBG_ERROR(("invalid address %08x", uipAddr));
  1298. rc = DBGERR_INVALID_CMD;
  1299. }
  1300. if (fPhysical && (pbData != NULL))
  1301. {
  1302. MapUnmapPhysMem(NULL, (ULONG_PTR)pbData, dwLen, NULL);
  1303. }
  1304. return rc;
  1305. } //DumpData
  1306. /***LP DebugDumpData - Dump data to debugger
  1307. *
  1308. * ENTRY
  1309. * pArg -> argument type entry
  1310. * pszArg -> argument string
  1311. * dwfDataSize - data size flags
  1312. *
  1313. * EXIT-SUCCESS
  1314. * returns DBGERR_NONE
  1315. * EXIT-FAILURE
  1316. * returns negative error code
  1317. */
  1318. LONG LOCAL DebugDumpData(PCMDARG pArg, PSZ pszArg, ULONG dwfDataSize)
  1319. {
  1320. LONG rc = DBGERR_NONE;
  1321. static BOOLEAN fProcessed = FALSE;
  1322. #define DEF_LEN 0x80
  1323. static ULONG dwLen = DEF_LEN;
  1324. if (pszArg != NULL)
  1325. {
  1326. if ((pArg != NULL) && (pArg->dwArgType == AT_NUM))
  1327. {
  1328. dwLen = dwCmdArg;
  1329. }
  1330. else
  1331. {
  1332. ULONG_PTR uipAddr;
  1333. BOOLEAN fPhysical;
  1334. if (((rc = DebugExpr(pszArg, &uipAddr, &fPhysical, NULL, NULL)) ==
  1335. DBGERR_NONE) &&
  1336. ((rc = DumpData(uipAddr, dwfDataSize, dwLen, fPhysical)) ==
  1337. DBGERR_NONE))
  1338. {
  1339. fProcessed = TRUE;
  1340. }
  1341. }
  1342. }
  1343. else
  1344. {
  1345. if (fProcessed)
  1346. fProcessed = FALSE;
  1347. else
  1348. {
  1349. rc = DumpData(gDebugger.uipDumpDataAddr, dwfDataSize, dwLen,
  1350. (BOOLEAN)((gDebugger.dwfDebugger &
  1351. DBGF_DUMPDATA_PHYADDR) != 0));
  1352. }
  1353. dwLen = DEF_LEN;
  1354. }
  1355. return rc;
  1356. } //DebugDumpData
  1357. /***LP DebugD - Dump data
  1358. *
  1359. * ENTRY
  1360. * pArg -> argument type entry
  1361. * pszArg -> argument string
  1362. * dwArgNum - argument number
  1363. * dwNonSWArgs - number of non-switch arguments
  1364. *
  1365. * EXIT-SUCCESS
  1366. * returns DBGERR_NONE
  1367. * EXIT-FAILURE
  1368. * returns negative error code
  1369. */
  1370. LONG LOCAL DebugD(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum, ULONG dwNonSWArgs)
  1371. {
  1372. LONG rc;
  1373. DEREF(dwArgNum);
  1374. DEREF(dwNonSWArgs);
  1375. rc = DebugDumpData(pArg, pszArg,
  1376. gDebugger.dwfDebugger & DBGF_DUMPDATA_MASK);
  1377. return rc;
  1378. } //DebugD
  1379. /***LP DebugDB - Dump data bytes
  1380. *
  1381. * ENTRY
  1382. * pArg -> argument type entry
  1383. * pszArg -> argument string
  1384. * dwArgNum - argument number
  1385. * dwNonSWArgs - number of non-switch arguments
  1386. *
  1387. * EXIT-SUCCESS
  1388. * returns DBGERR_NONE
  1389. * EXIT-FAILURE
  1390. * returns negative error code
  1391. */
  1392. LONG LOCAL DebugDB(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum, ULONG dwNonSWArgs)
  1393. {
  1394. LONG rc;
  1395. DEREF(dwArgNum);
  1396. DEREF(dwNonSWArgs);
  1397. rc = DebugDumpData(pArg, pszArg, DBGF_DUMPDATA_BYTE);
  1398. return rc;
  1399. } //DebugDB
  1400. /***LP DebugDW - Dump data words
  1401. *
  1402. * ENTRY
  1403. * pArg -> argument type entry
  1404. * pszArg -> argument string
  1405. * dwArgNum - argument number
  1406. * dwNonSWArgs - number of non-switch arguments
  1407. *
  1408. * EXIT-SUCCESS
  1409. * returns DBGERR_NONE
  1410. * EXIT-FAILURE
  1411. * returns negative error code
  1412. */
  1413. LONG LOCAL DebugDW(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum, ULONG dwNonSWArgs)
  1414. {
  1415. LONG rc;
  1416. DEREF(dwArgNum);
  1417. DEREF(dwNonSWArgs);
  1418. rc = DebugDumpData(pArg, pszArg, DBGF_DUMPDATA_WORD);
  1419. return rc;
  1420. } //DebugDW
  1421. /***LP DebugDD - Dump data dwords
  1422. *
  1423. * ENTRY
  1424. * pArg -> argument type entry
  1425. * pszArg -> argument string
  1426. * dwArgNum - argument number
  1427. * dwNonSWArgs - number of non-switch arguments
  1428. *
  1429. * EXIT-SUCCESS
  1430. * returns DBGERR_NONE
  1431. * EXIT-FAILURE
  1432. * returns negative error code
  1433. */
  1434. LONG LOCAL DebugDD(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum, ULONG dwNonSWArgs)
  1435. {
  1436. LONG rc;
  1437. DEREF(dwArgNum);
  1438. DEREF(dwNonSWArgs);
  1439. rc = DebugDumpData(pArg, pszArg, DBGF_DUMPDATA_DWORD);
  1440. return rc;
  1441. } //DebugDD
  1442. /***LP DebugDA - Dump data string
  1443. *
  1444. * ENTRY
  1445. * pArg -> argument type entry
  1446. * pszArg -> argument string
  1447. * dwArgNum - argument number
  1448. * dwNonSWArgs - number of non-switch arguments
  1449. *
  1450. * EXIT-SUCCESS
  1451. * returns DBGERR_NONE
  1452. * EXIT-FAILURE
  1453. * returns negative error code
  1454. */
  1455. LONG LOCAL DebugDA(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum, ULONG dwNonSWArgs)
  1456. {
  1457. LONG rc;
  1458. DEREF(dwArgNum);
  1459. DEREF(dwNonSWArgs);
  1460. rc = DebugDumpData(pArg, pszArg, DBGF_DUMPDATA_STRING);
  1461. return rc;
  1462. } //DebugDA
  1463. #ifdef DEBUG
  1464. /***LP DebugDC - Dump memory object count table
  1465. *
  1466. * ENTRY
  1467. * pArg -> argument type entry
  1468. * pszArg -> argument string
  1469. * dwArgNum - argument number
  1470. * dwNonSWArgs - number of non-switch arguments
  1471. *
  1472. * EXIT-SUCCESS
  1473. * returns DBGERR_NONE
  1474. * EXIT-FAILURE
  1475. * returns negative error code
  1476. */
  1477. LONG LOCAL DebugDC(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum, ULONG dwNonSWArgs)
  1478. {
  1479. LONG rc;
  1480. DEREF(pArg);
  1481. DEREF(dwArgNum);
  1482. DEREF(dwNonSWArgs);
  1483. if (pszArg == NULL)
  1484. {
  1485. DumpMemObjCounts();
  1486. rc = DBGERR_NONE;
  1487. }
  1488. else
  1489. {
  1490. DBG_ERROR(("invalid dump object count command"));
  1491. rc = DBGERR_INVALID_CMD;
  1492. }
  1493. return rc;
  1494. } //DebugDC
  1495. /***LP DebugDumpHeap - Dump heap
  1496. *
  1497. * ENTRY
  1498. * pArg -> argument type entry
  1499. * pszArg -> argument string
  1500. * dwArgNum - argument number
  1501. * dwNonSWArgs - number of non-switch arguments
  1502. *
  1503. * EXIT-SUCCESS
  1504. * returns DBGERR_NONE
  1505. * EXIT-FAILURE
  1506. * returns negative error code
  1507. */
  1508. LONG LOCAL DebugDumpHeap(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  1509. ULONG dwNonSWArgs)
  1510. {
  1511. LONG rc = DBGERR_NONE;
  1512. static BOOLEAN fAddr = FALSE;
  1513. static PHEAP pheap = NULL;
  1514. DEREF(pArg);
  1515. DEREF(dwArgNum);
  1516. DEREF(dwNonSWArgs);
  1517. if (pszArg != NULL)
  1518. {
  1519. if (!fAddr)
  1520. {
  1521. if (IsNumber(pszArg, 16, (PULONG_PTR)&pheap) &&
  1522. ASSERTRANGE(pheap, sizeof(HEAP)))
  1523. {
  1524. fAddr = TRUE;
  1525. }
  1526. else
  1527. {
  1528. DBG_ERROR(("invalid heap block address - %s", pszArg));
  1529. rc = DBGERR_INVALID_CMD;
  1530. }
  1531. }
  1532. else
  1533. {
  1534. DBG_ERROR(("invalid dump heap command"));
  1535. rc = DBGERR_INVALID_CMD;
  1536. }
  1537. }
  1538. else
  1539. {
  1540. if (!fAddr)
  1541. {
  1542. pheap = gpheapGlobal;
  1543. }
  1544. if (pheap->dwSig != SIG_HEAP)
  1545. {
  1546. DBG_ERROR(("invalid heap block at %x", pheap));
  1547. rc = DBGERR_CMD_FAILED;
  1548. }
  1549. else
  1550. {
  1551. for (pheap = pheap->pheapHead;
  1552. pheap != NULL;
  1553. pheap = pheap->pheapNext)
  1554. {
  1555. DumpHeap(pheap);
  1556. }
  1557. }
  1558. fAddr = FALSE;
  1559. }
  1560. return rc;
  1561. } //DebugDumpHeap
  1562. /***LP DumpHeap - Dump heap block
  1563. *
  1564. * ENTRY
  1565. * pheap -> HEAP
  1566. *
  1567. * EXIT
  1568. * None
  1569. */
  1570. VOID LOCAL DumpHeap(PHEAP pheap)
  1571. {
  1572. PHEAPOBJHDR phobj;
  1573. ASSERT(pheap->dwSig == SIG_HEAP);
  1574. PRINTF("HeapBlock=%08x, HeapEnd=%08x, HeapHead=%08x, HeapNext=%08x\n",
  1575. pheap, pheap->pbHeapEnd, pheap->pheapHead, pheap->pheapNext);
  1576. PRINTF("HeapTop=%08x, HeapFreeList=%08x, UsedHeapSize=%d bytes\n",
  1577. pheap->pbHeapTop, pheap->plistFreeHeap,
  1578. pheap->pbHeapTop - (PUCHAR)&pheap->Heap);
  1579. for (phobj = &pheap->Heap;
  1580. (PUCHAR)phobj < pheap->pbHeapTop;
  1581. phobj = (PHEAPOBJHDR)((PUCHAR)phobj + phobj->dwLen))
  1582. {
  1583. PRINTF("%08x: %s, Len=%08d, Prev=%08x, Next=%08x\n",
  1584. phobj, (phobj->dwSig == 0)? "free": NameSegString(phobj->dwSig),
  1585. phobj->dwLen, (phobj->dwSig == 0)? phobj->list.plistPrev: 0,
  1586. (phobj->dwSig == 0)? phobj->list.plistNext: 0);
  1587. }
  1588. } //DumpHeap
  1589. #endif
  1590. /***LP DebugDumpStack - Dump stack
  1591. *
  1592. * ENTRY
  1593. * pArg -> argument type entry
  1594. * pszArg -> argument string
  1595. * dwArgNum - argument number
  1596. * dwNonSWArgs - number of non-switch arguments
  1597. *
  1598. * EXIT-SUCCESS
  1599. * returns DBGERR_NONE
  1600. * EXIT-FAILURE
  1601. * returns negative error code
  1602. */
  1603. LONG LOCAL DebugDumpStack(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  1604. ULONG dwNonSWArgs)
  1605. {
  1606. LONG rc = DBGERR_NONE;
  1607. static BOOLEAN fAddr = FALSE;
  1608. static PCTXT pctxt = NULL;
  1609. DEREF(pArg);
  1610. DEREF(dwArgNum);
  1611. DEREF(dwNonSWArgs);
  1612. if (pszArg != NULL)
  1613. {
  1614. if (!fAddr)
  1615. {
  1616. if (IsNumber(pszArg, 16, (PULONG_PTR)&pctxt) &&
  1617. ASSERTRANGE(pctxt, sizeof(CTXT)))
  1618. {
  1619. fAddr = TRUE;
  1620. }
  1621. else
  1622. {
  1623. DBG_ERROR(("invalid context block address %s", pszArg));
  1624. rc = DBGERR_INVALID_CMD;
  1625. }
  1626. }
  1627. else
  1628. {
  1629. DBG_ERROR(("invalid dump stack command"));
  1630. rc = DBGERR_INVALID_CMD;
  1631. }
  1632. }
  1633. else
  1634. {
  1635. if (!fAddr)
  1636. {
  1637. pctxt = gReadyQueue.pctxtCurrent;
  1638. }
  1639. if ((pctxt == NULL) || (pctxt->dwSig != SIG_CTXT))
  1640. {
  1641. DBG_ERROR(("no current context or invalid context block at %x",
  1642. pctxt));
  1643. rc = DBGERR_CMD_FAILED;
  1644. }
  1645. else
  1646. {
  1647. DumpStack(pctxt, (BOOLEAN)((dwCmdArg & DSF_VERBOSE) != 0));
  1648. }
  1649. dwCmdArg = 0;
  1650. fAddr = FALSE;
  1651. }
  1652. return rc;
  1653. } //DebugDumpStack
  1654. /***LP DebugDumpLog - Dump event log
  1655. *
  1656. * ENTRY
  1657. * pArg -> argument type entry
  1658. * pszArg -> argument string
  1659. * dwArgNum - argument number
  1660. * dwNonSWArgs - number of non-switch arguments
  1661. *
  1662. * EXIT-SUCCESS
  1663. * returns DBGERR_NONE
  1664. * EXIT-FAILURE
  1665. * returns negative error code
  1666. */
  1667. LONG LOCAL DebugDumpLog(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  1668. ULONG dwNonSWArgs)
  1669. {
  1670. LONG rc;
  1671. TIME_FIELDS eventTime;
  1672. LARGE_INTEGER eventTimeInt;
  1673. DEREF(pArg);
  1674. DEREF(dwArgNum);
  1675. DEREF(dwNonSWArgs);
  1676. if (pszArg != NULL)
  1677. {
  1678. DBG_ERROR(("invalid DL command"));
  1679. rc = DBGERR_INVALID_CMD;
  1680. }
  1681. else if (gDebugger.pEventLog == NULL)
  1682. {
  1683. DBG_ERROR(("no event log allocated"));
  1684. rc = DBGERR_CMD_FAILED;
  1685. }
  1686. else
  1687. {
  1688. ULONG i;
  1689. PEVENTLOG plog;
  1690. PNSOBJ pns;
  1691. ULONG dwOffset;
  1692. PRINTF("\n");
  1693. for (i = gDebugger.dwLogIndex;;) {
  1694. if (gDebugger.pEventLog[i].dwEvent != 0) {
  1695. plog = &gDebugger.pEventLog[i];
  1696. eventTimeInt.QuadPart = plog->ullTime;
  1697. RtlTimeToTimeFields( &eventTimeInt, &eventTime );
  1698. PRINTF(
  1699. "%d:%02d:%02d.%03d: [%8x]",
  1700. eventTime.Hour,
  1701. eventTime.Minute,
  1702. eventTime.Second,
  1703. eventTime.Milliseconds,
  1704. plog->uipData1
  1705. );
  1706. switch (plog->dwEvent) {
  1707. case 'AMUT':
  1708. PRINTF("AcquireMutext ");
  1709. break;
  1710. case 'RMUT':
  1711. PRINTF("ReleaseMutext ");
  1712. break;
  1713. case 'INSQ':
  1714. PRINTF("InsertReadyQueue ");
  1715. break;
  1716. case 'NEST':
  1717. PRINTF("NestContext ");
  1718. break;
  1719. case 'EVAL':
  1720. PRINTF("EvaluateContext ");
  1721. break;
  1722. case 'QCTX':
  1723. PRINTF("QueueContext ");
  1724. break;
  1725. case 'REST':
  1726. PRINTF("RestartContext ");
  1727. break;
  1728. case 'KICK':
  1729. PRINTF("QueueWorkItem ");
  1730. break;
  1731. case 'PAUS':
  1732. PRINTF("PauseInterpreter ");
  1733. break;
  1734. case 'RSCB':
  1735. PRINTF("RestartCtxtCallback ");
  1736. break;
  1737. case 'DONE':
  1738. PRINTF("EvalMethodComplete ");
  1739. break;
  1740. case 'ASCB':
  1741. PRINTF("AsyncCallBack ");
  1742. break;
  1743. case 'NSYN':
  1744. PRINTF("NestedSyncEvalObject ");
  1745. break;
  1746. case 'SYNC':
  1747. PRINTF("SyncEvalObject ");
  1748. break;
  1749. case 'ASYN':
  1750. PRINTF("AsyncEvalObject ");
  1751. break;
  1752. case 'NASY':
  1753. PRINTF("NestedAsyncEvalObject ");
  1754. break;
  1755. case 'RUNC':
  1756. PRINTF("RunContext ");
  1757. break;
  1758. case 'PACB':
  1759. PRINTF("PauseAsyncCallback ");
  1760. break;
  1761. case 'RUN!':
  1762. PRINTF("FinishedContext ");
  1763. break;
  1764. case 'RSUM':
  1765. PRINTF("ResumeInterpreter ");
  1766. break;
  1767. case 'RSTQ':
  1768. PRINTF("ResumeQueueWorkItem ");
  1769. break;
  1770. default:
  1771. break;
  1772. }
  1773. switch (plog->dwEvent)
  1774. {
  1775. case 'AMUT':
  1776. case 'RMUT':
  1777. PRINTF("\n Mut=%08x Owner=%08x dwcOwned=%d rc=%x\n",
  1778. plog->uipData2, plog->uipData3,
  1779. plog->uipData4, plog->uipData5);
  1780. break;
  1781. case 'INSQ':
  1782. case 'NEST':
  1783. case 'EVAL':
  1784. case 'QCTX':
  1785. case 'REST':
  1786. PRINTF("Context=%08x\n %s\n QTh=%08x QCt=%08x QFg=%08x",
  1787. plog->uipData5,
  1788. GetObjectPath((PNSOBJ)plog->uipData6),
  1789. plog->uipData2, plog->uipData3,
  1790. plog->uipData4
  1791. );
  1792. if (FindObjSymbol((PUCHAR)plog->uipData7, &pns,
  1793. &dwOffset)) {
  1794. PRINTF(" pbOp=%s", GetObjectPath(pns));
  1795. if (dwOffset != 0) {
  1796. PRINTF("+%x", dwOffset);
  1797. }
  1798. }
  1799. PRINTF("\n");
  1800. break;
  1801. case 'KICK':
  1802. case 'PAUS':
  1803. PRINTF("\n QTh=%08x QCt=%08x QFg=%08x rc=%x\n",
  1804. plog->uipData2, plog->uipData3,
  1805. plog->uipData4, plog->uipData5);
  1806. break;
  1807. case 'RSCB':
  1808. PRINTF("Context=%08x\n QTh=%08x QCt=%08x QFg=%08x\n",
  1809. plog->uipData5, plog->uipData2,
  1810. plog->uipData3, plog->uipData4);
  1811. break;
  1812. case 'DONE':
  1813. case 'ASCB':
  1814. PRINTF("rc=%x pEvent=%x\n %s\n QTh=%08x QCt=%08x QFg=%08x\n",
  1815. plog->uipData6, plog->uipData7,
  1816. GetObjectPath((PNSOBJ)plog->uipData5),
  1817. plog->uipData2, plog->uipData3,
  1818. plog->uipData4
  1819. );
  1820. break;
  1821. case 'NSYN':
  1822. case 'SYNC':
  1823. case 'ASYN':
  1824. PRINTF("IRQL=%2x\n %s\n QTh=%08x QCt=%08x QFg=%08x\n",
  1825. plog->uipData5 & 0xff,
  1826. GetObjectPath((PNSOBJ)plog->uipData6),
  1827. plog->uipData2, plog->uipData3,
  1828. plog->uipData4
  1829. );
  1830. break;
  1831. case 'NASY':
  1832. PRINTF("Context=%x CallBack=%x\n %s\n QTh=%08x QCt=%08x QFg=%08x\n",
  1833. plog->uipData6, plog->uipData7,
  1834. GetObjectPath((PNSOBJ)plog->uipData5),
  1835. plog->uipData2, plog->uipData3,
  1836. plog->uipData4
  1837. );
  1838. break;
  1839. case 'RUNC':
  1840. PRINTF("Context=%x\n %s\n QTh=%08x QCt=%08x QFg=%08x\n",
  1841. plog->uipData5, GetObjectPath((PNSOBJ)plog->uipData6),
  1842. plog->uipData2, plog->uipData3,
  1843. plog->uipData4
  1844. );
  1845. break;
  1846. case 'PACB':
  1847. case 'RUN!':
  1848. PRINTF("Context=%x rc=%x\n QTh=%08x QCt=%08x QFg=%08x\n",
  1849. plog->uipData5, plog->uipData6,
  1850. plog->uipData2, plog->uipData3,
  1851. plog->uipData4
  1852. );
  1853. break;
  1854. case 'RSUM':
  1855. case 'RSTQ':
  1856. PRINTF("\n QTh=%08x QCt=%08x QFg=%08x\n",
  1857. plog->uipData2, plog->uipData3,
  1858. plog->uipData4);
  1859. break;
  1860. default:
  1861. PRINTF("D1=%08x,D2=%08x,D3=%08x,D4=%08x,D5=%08x,D6=%08x,D7=%08x\n",
  1862. plog->uipData1, plog->uipData2, plog->uipData3,
  1863. plog->uipData4, plog->uipData5, plog->uipData6,
  1864. plog->uipData7);
  1865. }
  1866. }
  1867. PRINTF("\n");
  1868. if (++i >= gDebugger.dwLogSize)
  1869. {
  1870. i = 0;
  1871. }
  1872. if (i == gDebugger.dwLogIndex)
  1873. {
  1874. break;
  1875. }
  1876. }
  1877. rc = DBGERR_NONE;
  1878. }
  1879. return rc;
  1880. } //DebugDumpLog
  1881. /***LP DumpStack - Dump stack of a context block
  1882. *
  1883. * ENTRY
  1884. * pctxt -> CTXT
  1885. * fVerbose - TRUE if verbose mode on
  1886. *
  1887. * EXIT
  1888. * None
  1889. */
  1890. VOID LOCAL DumpStack(PCTXT pctxt, BOOLEAN fVerbose)
  1891. {
  1892. PFRAMEHDR pfh;
  1893. PUCHAR pbOp = NULL;
  1894. ASSERT(pctxt->dwSig == SIG_CTXT);
  1895. if (fVerbose)
  1896. {
  1897. PRINTF("CtxtBlock=%x, StackTop=%x, StackEnd=%x\n\n",
  1898. pctxt, pctxt->LocalHeap.pbHeapEnd, pctxt->pbCtxtEnd);
  1899. }
  1900. for (pfh = (PFRAMEHDR)pctxt->LocalHeap.pbHeapEnd;
  1901. (PUCHAR)pfh < pctxt->pbCtxtEnd;
  1902. pfh = (PFRAMEHDR)((PUCHAR)pfh + pfh->dwLen))
  1903. {
  1904. if (fVerbose)
  1905. {
  1906. PRINTF("%08x: %s, Len=%08d, FrameFlags=%08x, ParseFunc=%08x\n",
  1907. pfh, NameSegString(pfh->dwSig), pfh->dwLen, pfh->dwfFrame,
  1908. pfh->pfnParse);
  1909. }
  1910. if (pfh->dwSig == SIG_CALL)
  1911. {
  1912. PCALL pcall = (PCALL)pfh;
  1913. int i;
  1914. //
  1915. // This is a call frame, dump it.
  1916. //
  1917. PRINTF("%08x: %s(", pbOp, GetObjectPath(pcall->pnsMethod));
  1918. for (i = 0; i < pcall->icArgs; ++i)
  1919. {
  1920. DumpObject(&pcall->pdataArgs[i], NULL, -1);
  1921. if (i + 1 < pcall->icArgs)
  1922. {
  1923. PRINTF(",");
  1924. }
  1925. }
  1926. PRINTF(")\n");
  1927. if (fVerbose)
  1928. {
  1929. for (i = 0; i < MAX_NUM_LOCALS; ++i)
  1930. {
  1931. PRINTF("Local%d: ", i);
  1932. DumpObject(&pcall->Locals[i], NULL, 0);
  1933. }
  1934. }
  1935. }
  1936. else if (pfh->dwSig == SIG_SCOPE)
  1937. {
  1938. pbOp = ((PSCOPE)pfh)->pbOpRet;
  1939. }
  1940. }
  1941. } //DumpStack
  1942. /***LP DebugDumpNameSpace - Dump Name Space
  1943. *
  1944. * ENTRY
  1945. * pArg -> argument type entry
  1946. * pszArg -> argument string
  1947. * dwArgNum - argument number
  1948. * dwNonSWArgs - number of non-switch arguments
  1949. *
  1950. * EXIT-SUCCESS
  1951. * returns DBGERR_NONE
  1952. * EXIT-FAILURE
  1953. * returns negative error code
  1954. */
  1955. LONG LOCAL DebugDumpNameSpace(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  1956. ULONG dwNonSWArgs)
  1957. {
  1958. LONG rc = DBGERR_NONE;
  1959. static BOOLEAN fProcessed = FALSE;
  1960. DEREF(pArg);
  1961. DEREF(dwArgNum);
  1962. DEREF(dwNonSWArgs);
  1963. //
  1964. // User specified name space path or name space node address
  1965. //
  1966. if (pszArg != NULL)
  1967. {
  1968. PNSOBJ pns;
  1969. PSZ psz;
  1970. pns = (PNSOBJ)UlongToPtr(STRTOUL(pszArg, &psz, 16));
  1971. if ((psz == pszArg) || (*psz != '\0'))
  1972. {
  1973. //
  1974. // The argument is not an address, could be a name space path.
  1975. //
  1976. STRUPR(pszArg);
  1977. rc = DumpNameSpaceObject(pszArg,
  1978. (BOOLEAN)((dwCmdArg & DNSF_RECURSE) != 0));
  1979. }
  1980. else if (ASSERTRANGE(pns, sizeof(NSOBJ)))
  1981. {
  1982. PRINTF("\nACPI Name Space: %s (%x)\n", GetObjectPath(pns), pns);
  1983. if (dwCmdArg & DNSF_RECURSE)
  1984. DumpNameSpaceTree(pns, 0);
  1985. else
  1986. DumpObject(&pns->ObjData, NameSegString(pns->dwNameSeg), 0);
  1987. }
  1988. else
  1989. {
  1990. DBG_ERROR(("invalid name space address - %s", pszArg));
  1991. rc = DBGERR_INVALID_CMD;
  1992. }
  1993. if (rc == DBGERR_NONE)
  1994. fProcessed = TRUE;
  1995. }
  1996. else
  1997. { //
  1998. // User typed "dns" but did not specify any name space path or address
  1999. //
  2000. if (!fProcessed)
  2001. {
  2002. rc = DumpNameSpaceObject(NAMESTR_ROOT, TRUE);
  2003. }
  2004. dwCmdArg = 0;
  2005. fProcessed = FALSE;
  2006. }
  2007. return rc;
  2008. } //DebugDumpNameSpace
  2009. /***LP DebugDumpObject - Dump data object
  2010. *
  2011. * ENTRY
  2012. * pArg -> argument type entry
  2013. * pszArg -> argument string
  2014. * dwArgNum - argument number
  2015. * dwNonSWArgs - number of non-switch arguments
  2016. *
  2017. * EXIT-SUCCESS
  2018. * returns DBGERR_NONE
  2019. * EXIT-FAILURE
  2020. * returns negative error code
  2021. */
  2022. LONG LOCAL DebugDumpObject(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  2023. ULONG dwNonSWArgs)
  2024. {
  2025. LONG rc = DBGERR_NONE;
  2026. DEREF(pArg);
  2027. DEREF(dwArgNum);
  2028. DEREF(dwNonSWArgs);
  2029. //
  2030. // User specified object address
  2031. //
  2032. if (pszArg != NULL)
  2033. {
  2034. POBJDATA pdata;
  2035. PSZ psz;
  2036. pdata = (POBJDATA)UlongToPtr(STRTOUL(pszArg, &psz, 16));
  2037. if ((psz != pszArg) && (*psz == '\0') &&
  2038. ASSERTRANGE(pdata, sizeof(OBJDATA)))
  2039. {
  2040. DumpObject(pdata, NULL, 0);
  2041. }
  2042. else
  2043. {
  2044. DBG_ERROR(("invalid name space object or object is not a method - %s",
  2045. pszArg));
  2046. rc = DBGERR_INVALID_CMD;
  2047. }
  2048. }
  2049. return rc;
  2050. } //DebugDumpObject
  2051. /***LP DebugEditMem - Edit memory
  2052. *
  2053. * ENTRY
  2054. * pArg -> argument type entry
  2055. * pszArg -> argument string
  2056. * dwfDataSize - data size flags
  2057. *
  2058. * EXIT-SUCCESS
  2059. * returns DBGERR_NONE
  2060. * EXIT-FAILURE
  2061. * returns negative error code
  2062. */
  2063. LONG LOCAL DebugEditMem(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  2064. ULONG dwNonSWArgs)
  2065. {
  2066. LONG rc = DBGERR_NONE;
  2067. static BOOLEAN fProcessed = FALSE;
  2068. static BOOLEAN fPhysical = FALSE;
  2069. static ULONG_PTR uipAddr = 0;
  2070. DEREF(pArg);
  2071. DEREF(dwArgNum);
  2072. DEREF(dwNonSWArgs);
  2073. if (pszArg != NULL)
  2074. {
  2075. ULONG_PTR uipData;
  2076. PUCHAR pbMemAddr;
  2077. if (dwArgNum == 1)
  2078. {
  2079. if ((pszArg[0] == '%') && (pszArg[0] == '%'))
  2080. {
  2081. if (IsNumber(&pszArg[2], 16, &uipData))
  2082. {
  2083. fPhysical = TRUE;
  2084. uipAddr = uipData;
  2085. }
  2086. else
  2087. {
  2088. DBG_ERROR(("invalid physical address - %s", pszArg));
  2089. rc = DBGERR_INVALID_CMD;
  2090. }
  2091. }
  2092. else if (IsNumber(pszArg, 16, &uipData))
  2093. {
  2094. uipAddr = uipData;
  2095. }
  2096. else
  2097. {
  2098. DBG_ERROR(("invalid address - %s", pszArg));
  2099. rc = DBGERR_INVALID_CMD;
  2100. }
  2101. }
  2102. else if (IsNumber(pszArg, 16, &uipData))
  2103. {
  2104. if (uipData <= MAX_BYTE)
  2105. {
  2106. if (fPhysical)
  2107. {
  2108. if (MapUnmapPhysMem(NULL, uipAddr, 1,
  2109. (PULONG_PTR)&pbMemAddr) !=
  2110. STATUS_SUCCESS)
  2111. {
  2112. DBG_ERROR(("Failed to map physical address %p",
  2113. uipAddr));
  2114. rc = DBGERR_CMD_FAILED;
  2115. }
  2116. }
  2117. else
  2118. pbMemAddr = (PUCHAR)uipAddr;
  2119. if (ASSERTRANGE(pbMemAddr, 1))
  2120. {
  2121. *pbMemAddr = (UCHAR)uipData;
  2122. uipAddr++;
  2123. }
  2124. else
  2125. {
  2126. DBG_ERROR(("invalid address - %s", uipAddr));
  2127. rc = DBGERR_INVALID_CMD;
  2128. }
  2129. if (fPhysical)
  2130. {
  2131. MapUnmapPhysMem(NULL, (ULONG_PTR)pbMemAddr, 1, NULL);
  2132. }
  2133. }
  2134. else
  2135. {
  2136. DBG_ERROR(("data must be a byte value - %s", pszArg));
  2137. rc = DBGERR_INVALID_CMD;
  2138. }
  2139. }
  2140. else if ((pszArg[0] == '"') && (pszArg[STRLEN(pszArg) - 1] == '"'))
  2141. {
  2142. int i, icLen;
  2143. icLen = STRLEN(pszArg);
  2144. if (fPhysical)
  2145. {
  2146. if (MapUnmapPhysMem(NULL, uipAddr, icLen,
  2147. (PULONG_PTR)&pbMemAddr) != STATUS_SUCCESS)
  2148. {
  2149. DBG_ERROR(("Failed to map physical address %p", uipAddr));
  2150. rc = DBGERR_CMD_FAILED;
  2151. }
  2152. }
  2153. else
  2154. pbMemAddr = (PUCHAR)uipAddr;
  2155. if (ASSERTRANGE(pbMemAddr, icLen))
  2156. {
  2157. for (i = 1; i < icLen - 1; ++i)
  2158. {
  2159. *pbMemAddr = pszArg[i];
  2160. pbMemAddr++;
  2161. uipAddr++;
  2162. }
  2163. }
  2164. else
  2165. {
  2166. DBG_ERROR(("invalid address - %s", uipAddr));
  2167. rc = DBGERR_INVALID_CMD;
  2168. }
  2169. if (fPhysical)
  2170. {
  2171. MapUnmapPhysMem(NULL, (ULONG_PTR)pbMemAddr, icLen, NULL);
  2172. }
  2173. }
  2174. else
  2175. {
  2176. DBG_ERROR(("invalid data - %s", pszArg));
  2177. rc = DBGERR_INVALID_CMD;
  2178. }
  2179. if ((rc == DBGERR_NONE) && (dwArgNum > 1))
  2180. fProcessed = TRUE;
  2181. }
  2182. else
  2183. {
  2184. if (fProcessed)
  2185. fProcessed = FALSE;
  2186. else
  2187. {
  2188. DBG_ERROR(("invalid EditMemory command"));
  2189. rc = DBGERR_INVALID_CMD;
  2190. }
  2191. fPhysical = FALSE;
  2192. }
  2193. return rc;
  2194. } //DebugEditMem
  2195. /***LP DebugFindNSObj - Find NameSpace Object
  2196. *
  2197. * ENTRY
  2198. * pArg -> argument type entry
  2199. * pszArg -> argument string
  2200. * dwfDataSize - data size flags
  2201. *
  2202. * EXIT-SUCCESS
  2203. * returns DBGERR_NONE
  2204. * EXIT-FAILURE
  2205. * returns negative error code
  2206. */
  2207. LONG LOCAL DebugFindNSObj(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  2208. ULONG dwNonSWArgs)
  2209. {
  2210. LONG rc = DBGERR_NONE;
  2211. static BOOLEAN fProcessed = FALSE;
  2212. DEREF(pArg);
  2213. DEREF(dwArgNum);
  2214. DEREF(dwNonSWArgs);
  2215. if (pszArg != NULL)
  2216. {
  2217. ULONG dwLen;
  2218. dwLen = STRLEN(pszArg);
  2219. STRUPR(pszArg);
  2220. if (dwLen > sizeof(NAMESEG))
  2221. {
  2222. DBG_ERROR(("invalid NameSeg - %s", pszArg));
  2223. rc = DBGERR_INVALID_CMD;
  2224. }
  2225. else
  2226. {
  2227. NAMESEG dwName;
  2228. dwName = NAMESEG_BLANK;
  2229. MEMCPY(&dwName, pszArg, dwLen);
  2230. if (!FindNSObj(dwName, gpnsNameSpaceRoot))
  2231. {
  2232. PRINTF("No such NameSpace object - %s\n", pszArg);
  2233. }
  2234. fProcessed = TRUE;
  2235. }
  2236. }
  2237. else
  2238. {
  2239. if (fProcessed)
  2240. fProcessed = FALSE;
  2241. else
  2242. {
  2243. DBG_ERROR(("invalid Find command"));
  2244. rc = DBGERR_INVALID_CMD;
  2245. }
  2246. }
  2247. return rc;
  2248. } //DebugFindNSObj
  2249. /***LP FindNSObj - Find and print the full path of a name space object
  2250. *
  2251. * ENTRY
  2252. * dwName - NameSeg of the name space object
  2253. * pnsRoot -> root of NameSpace node to start the search
  2254. *
  2255. * EXIT-SUCCESS
  2256. * returns TRUE - found at least one match
  2257. * EXIT-FAILURE
  2258. * returns FALSE - found no match
  2259. */
  2260. BOOLEAN LOCAL FindNSObj(NAMESEG dwName, PNSOBJ pnsRoot)
  2261. {
  2262. BOOLEAN rc = FALSE;
  2263. if (pnsRoot != NULL)
  2264. {
  2265. if (dwName == pnsRoot->dwNameSeg)
  2266. {
  2267. PRINTF("%s\n", GetObjectPath(pnsRoot));
  2268. rc = TRUE;
  2269. }
  2270. if (pnsRoot->pnsFirstChild != NULL)
  2271. {
  2272. PNSOBJ pns, pnsNext;
  2273. for (pns = pnsRoot->pnsFirstChild; pns != NULL; pns = pnsNext)
  2274. {
  2275. pnsNext = ((PNSOBJ)pns->list.plistNext ==
  2276. pnsRoot->pnsFirstChild)?
  2277. NULL: (PNSOBJ)pns->list.plistNext;
  2278. rc |= FindNSObj(dwName, pns);
  2279. }
  2280. }
  2281. }
  2282. return rc;
  2283. } //FindNSObj
  2284. /***LP InPort - Read from an I/O port
  2285. *
  2286. * dwPort - port address
  2287. * dwSize - port size
  2288. * pdwData -> to hold data read
  2289. *
  2290. * EXIT-SUCCESS
  2291. * returns DBGERR_NONE
  2292. * EXIT-FAILURE
  2293. * returns negative error code
  2294. */
  2295. LONG LOCAL InPort(ULONG dwPort, ULONG dwSize, PULONG pdwData)
  2296. {
  2297. LONG rc = DBGERR_NONE;
  2298. PHYSICAL_ADDRESS phyaddr = {0, 0}, XlatedAddr;
  2299. ULONG dwAddrSpace;
  2300. phyaddr.LowPart = dwPort;
  2301. dwAddrSpace = 1;
  2302. if (HalTranslateBusAddress(Internal, 0, phyaddr, &dwAddrSpace, &XlatedAddr))
  2303. {
  2304. dwPort = XlatedAddr.LowPart;
  2305. *pdwData = ReadSystemIO(dwPort, dwSize, 0xffffffff);
  2306. }
  2307. else
  2308. {
  2309. DBG_ERROR(("failed to translate port address"));
  2310. rc = DBGERR_CMD_FAILED;
  2311. }
  2312. return rc;
  2313. } //InPort
  2314. /***LP DebugInPort - Port input
  2315. *
  2316. * ENTRY
  2317. * pszArg -> argument string
  2318. * dwSize - port size
  2319. *
  2320. * EXIT-SUCCESS
  2321. * returns DBGERR_NONE
  2322. * EXIT-FAILURE
  2323. * returns negative error code
  2324. */
  2325. LONG LOCAL DebugInPort(PSZ pszArg, ULONG dwSize)
  2326. {
  2327. LONG rc = DBGERR_NONE;
  2328. static BOOLEAN fProcessed = FALSE;
  2329. if (pszArg != NULL)
  2330. {
  2331. ULONG_PTR uipPort;
  2332. if (fProcessed || !IsNumber(pszArg, 16, &uipPort))
  2333. {
  2334. DBG_ERROR(("invalid inport command"));
  2335. rc = DBGERR_INVALID_CMD;
  2336. }
  2337. else
  2338. {
  2339. ULONG dwData;
  2340. if ((rc = InPort((ULONG)uipPort, dwSize, &dwData)) == DBGERR_NONE)
  2341. {
  2342. PRINTF("%04x: ", (ULONG)uipPort);
  2343. switch (dwSize)
  2344. {
  2345. case sizeof(UCHAR):
  2346. PRINTF("%02x", (UCHAR)dwData);
  2347. break;
  2348. case sizeof(USHORT):
  2349. PRINTF("%04x", (USHORT)dwData);
  2350. break;
  2351. case sizeof(ULONG):
  2352. PRINTF("%08x", dwData);
  2353. }
  2354. PRINTF("\n");
  2355. }
  2356. }
  2357. if (rc == DBGERR_NONE)
  2358. fProcessed = TRUE;
  2359. }
  2360. else
  2361. {
  2362. if (fProcessed)
  2363. fProcessed = FALSE;
  2364. else
  2365. {
  2366. DBG_ERROR(("invalid inport command"));
  2367. rc = DBGERR_INVALID_CMD;
  2368. }
  2369. }
  2370. return rc;
  2371. } //DebugInPort
  2372. /***LP DebugI - Byte port input
  2373. *
  2374. * ENTRY
  2375. * pArg -> argument type entry
  2376. * pszArg -> argument string
  2377. * dwArgNum - argument number
  2378. * dwNonSWArgs - number of non-switch arguments
  2379. *
  2380. * EXIT-SUCCESS
  2381. * returns DBGERR_NONE
  2382. * EXIT-FAILURE
  2383. * returns negative error code
  2384. */
  2385. LONG LOCAL DebugI(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum, ULONG dwNonSWArgs)
  2386. {
  2387. LONG rc;
  2388. DEREF(pArg);
  2389. DEREF(dwArgNum);
  2390. DEREF(dwNonSWArgs);
  2391. rc = DebugInPort(pszArg, sizeof(UCHAR));
  2392. return rc;
  2393. } //DebugI
  2394. /***LP DebugIW - Word port input
  2395. *
  2396. * ENTRY
  2397. * pArg -> argument type entry
  2398. * pszArg -> argument string
  2399. * dwArgNum - argument number
  2400. * dwNonSWArgs - number of non-switch arguments
  2401. *
  2402. * EXIT-SUCCESS
  2403. * returns DBGERR_NONE
  2404. * EXIT-FAILURE
  2405. * returns negative error code
  2406. */
  2407. LONG LOCAL DebugIW(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum, ULONG dwNonSWArgs)
  2408. {
  2409. LONG rc;
  2410. DEREF(pArg);
  2411. DEREF(dwArgNum);
  2412. DEREF(dwNonSWArgs);
  2413. rc = DebugInPort(pszArg, sizeof(USHORT));
  2414. return rc;
  2415. } //DebugIW
  2416. /***LP DebugID - DWord port input
  2417. *
  2418. * ENTRY
  2419. * pArg -> argument type entry
  2420. * pszArg -> argument string
  2421. * dwArgNum - argument number
  2422. * dwNonSWArgs - number of non-switch arguments
  2423. *
  2424. * EXIT-SUCCESS
  2425. * returns DBGERR_NONE
  2426. * EXIT-FAILURE
  2427. * returns negative error code
  2428. */
  2429. LONG LOCAL DebugID(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum, ULONG dwNonSWArgs)
  2430. {
  2431. LONG rc;
  2432. DEREF(pArg);
  2433. DEREF(dwArgNum);
  2434. DEREF(dwNonSWArgs);
  2435. rc = DebugInPort(pszArg, sizeof(ULONG));
  2436. return rc;
  2437. } //DebugID
  2438. /***LP DebugQuit - Quit to kernel debugger
  2439. *
  2440. * ENTRY
  2441. * pArg -> argument type entry
  2442. * pszArg -> argument string
  2443. * dwArgNum - argument number
  2444. * dwNonSWArgs - number of non-switch arguments
  2445. *
  2446. * EXIT-SUCCESS
  2447. * returns DBGERR_NONE
  2448. * EXIT-FAILURE
  2449. * returns negative error code
  2450. */
  2451. LONG LOCAL DebugQuit(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  2452. ULONG dwNonSWArgs)
  2453. {
  2454. LONG rc;
  2455. DEREF(pArg);
  2456. DEREF(dwArgNum);
  2457. DEREF(dwNonSWArgs);
  2458. if (pszArg == NULL)
  2459. {
  2460. if (gDebugger.dwfDebugger & DBGF_IN_VXDMODE)
  2461. {
  2462. rc = DBGERR_QUIT;
  2463. }
  2464. else
  2465. {
  2466. PRINTF("\nShell to Kernel Debugger.\n"
  2467. "Type 'g' to go back to the AML debugger.\n\n");
  2468. gDebugger.dwfDebugger |= DBGF_IN_KDSHELL;
  2469. KdBreakPoint();
  2470. gDebugger.dwfDebugger &= ~DBGF_IN_KDSHELL;
  2471. rc = DBGERR_NONE;
  2472. }
  2473. }
  2474. else
  2475. {
  2476. DBG_ERROR(("invalid Quit command"));
  2477. rc = DBGERR_INVALID_CMD;
  2478. }
  2479. return rc;
  2480. } //DebugQuit
  2481. /***LP DebugListCtxts - List all contexts
  2482. *
  2483. * ENTRY
  2484. * pArg -> argument type entry
  2485. * pszArg -> argument string
  2486. * dwArgNum - argument number
  2487. * dwNonSWArgs - number of non-switch arguments
  2488. *
  2489. * EXIT-SUCCESS
  2490. * returns DBGERR_NONE
  2491. * EXIT-FAILURE
  2492. * returns negative error code
  2493. */
  2494. LONG LOCAL DebugListCtxts(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  2495. ULONG dwNonSWArgs)
  2496. {
  2497. LONG rc;
  2498. DEREF(pArg);
  2499. DEREF(dwArgNum);
  2500. DEREF(dwNonSWArgs);
  2501. if (pszArg == NULL)
  2502. {
  2503. PLIST plist, plistNext;
  2504. PCTXT pctxt;
  2505. for (plist = gplistCtxtHead; plist != NULL; plist = plistNext)
  2506. {
  2507. plistNext = (plist->plistNext == gplistCtxtHead)?
  2508. NULL: plist->plistNext;
  2509. pctxt = CONTAINING_RECORD(plist, CTXT, listCtxt);
  2510. PRINTF("%cCtxt=%08x, ThID=%08x, Flgs=%c%c%c%c%c%c%c%c%c, pbOp=%08x, Obj=%s\n",
  2511. (pctxt == gReadyQueue.pctxtCurrent)? '*': ' ', pctxt,
  2512. (pctxt == gReadyQueue.pctxtCurrent)?
  2513. gReadyQueue.pkthCurrent: 0,
  2514. (pctxt->dwfCtxt & CTXTF_ASYNC_EVAL)? 'A': '-',
  2515. (pctxt->dwfCtxt & CTXTF_NEST_EVAL)? 'N': '-',
  2516. (pctxt->dwfCtxt & CTXTF_IN_READYQ)? 'Q': '-',
  2517. (pctxt->dwfCtxt & CTXTF_NEED_CALLBACK)? 'C': '-',
  2518. (pctxt->dwfCtxt & CTXTF_RUNNING)? 'R': '-',
  2519. (pctxt->dwfCtxt & CTXTF_READY)? 'W': '-',
  2520. (pctxt->dwfCtxt & CTXTF_TIMEOUT)? 'T': '-',
  2521. (pctxt->dwfCtxt & CTXTF_TIMER_DISPATCH)? 'D': '-',
  2522. (pctxt->dwfCtxt & CTXTF_TIMER_PENDING)? 'P': '-',
  2523. pctxt->pbOp, GetObjectPath(pctxt->pnsObj));
  2524. }
  2525. rc = DBGERR_NONE;
  2526. }
  2527. else
  2528. {
  2529. DBG_ERROR(("invalid LC command"));
  2530. rc = DBGERR_INVALID_CMD;
  2531. }
  2532. return rc;
  2533. } //DebugListCtxts
  2534. /***LP DebugLN - Display nearest symbol
  2535. *
  2536. * ENTRY
  2537. * pArg -> argument type entry
  2538. * pszArg -> argument string
  2539. * dwArgNum - argument number
  2540. * dwNonSWArgs - number of non-switch arguments
  2541. *
  2542. * EXIT-SUCCESS
  2543. * returns DBGERR_NONE
  2544. * EXIT-FAILURE
  2545. * returns negative error code
  2546. */
  2547. LONG LOCAL DebugLN(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum, ULONG dwNonSWArgs)
  2548. {
  2549. LONG rc = DBGERR_NONE;
  2550. static BOOLEAN fProcessed = FALSE;
  2551. DEREF(pArg);
  2552. DEREF(dwArgNum);
  2553. DEREF(dwNonSWArgs);
  2554. if (pszArg != NULL)
  2555. {
  2556. PUCHAR pb;
  2557. if ((rc = DebugExpr(pszArg, (PULONG_PTR)&pb, NULL, NULL, NULL)) ==
  2558. DBGERR_NONE)
  2559. {
  2560. PrintSymbol(pb);
  2561. }
  2562. if (rc == DBGERR_NONE)
  2563. fProcessed = TRUE;
  2564. }
  2565. else
  2566. {
  2567. if (fProcessed)
  2568. fProcessed = FALSE;
  2569. else if (gReadyQueue.pctxtCurrent == NULL)
  2570. {
  2571. DBG_ERROR(("no current context"));
  2572. rc = DBGERR_CMD_FAILED;
  2573. }
  2574. else
  2575. PrintSymbol(gReadyQueue.pctxtCurrent->pbOp);
  2576. }
  2577. return rc;
  2578. } //DebugLN
  2579. /***LP DummyCallBack - Callback that does absolutely nothing
  2580. *
  2581. * ENTRY
  2582. * pv - not used
  2583. *
  2584. * EXIT
  2585. * None
  2586. */
  2587. VOID LOCAL DummyCallBack(PVOID pv)
  2588. {
  2589. DEREF(pv);
  2590. } //DummyCallBack
  2591. /***LP DebugNotify - Notify object
  2592. *
  2593. * ENTRY
  2594. * pArg -> argument type entry
  2595. * pszArg -> argument string
  2596. * dwArgNum - argument number
  2597. * dwNonSWArgs - number of non-switch arguments
  2598. *
  2599. * EXIT-SUCCESS
  2600. * returns DBGERR_NONE
  2601. * EXIT-FAILURE
  2602. * returns negative error code
  2603. */
  2604. LONG LOCAL DebugNotify(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  2605. ULONG dwNonSWArgs)
  2606. {
  2607. LONG rc = DBGERR_NONE;
  2608. static PNSOBJ pns = NULL;
  2609. static ULONG_PTR uipValue = 0;
  2610. DEREF(pArg);
  2611. if (pszArg != NULL)
  2612. {
  2613. switch (dwArgNum)
  2614. {
  2615. case 1:
  2616. if (!IsNumber(pszArg, 16, (PULONG_PTR)&pns))
  2617. {
  2618. STRUPR(pszArg);
  2619. if (GetNameSpaceObject(pszArg, NULL, &pns, NSF_LOCAL_SCOPE)
  2620. != STATUS_SUCCESS)
  2621. {
  2622. DBG_ERROR(("object not found - %s", pszArg));
  2623. rc = DBGERR_INVALID_CMD;
  2624. }
  2625. }
  2626. break;
  2627. case 2:
  2628. if (!IsNumber(pszArg, 16, &uipValue))
  2629. {
  2630. DBG_ERROR(("invalid notification value - %s", pszArg));
  2631. rc = DBGERR_INVALID_CMD;
  2632. }
  2633. break;
  2634. default:
  2635. DBG_ERROR(("invalid notify command"));
  2636. rc = DBGERR_INVALID_CMD;
  2637. }
  2638. }
  2639. else
  2640. {
  2641. if (dwNonSWArgs != 2)
  2642. {
  2643. DBG_ERROR(("invalid notify command"));
  2644. rc = DBGERR_INVALID_CMD;
  2645. }
  2646. else if (!ASSERTRANGE(pns, sizeof(NSOBJ)))
  2647. {
  2648. DBG_ERROR(("invalid object"));
  2649. rc = DBGERR_INVALID_CMD;
  2650. }
  2651. else
  2652. {
  2653. PRINTF("Queuing: Notify(%s, %x) ...\n",
  2654. GetObjectPath(pns), uipValue);
  2655. ((PFNNH)ghNotify.pfnHandler)(EVTYPE_NOTIFY, (ULONG)uipValue, pns,
  2656. (ULONG)ghNotify.uipParam,
  2657. DummyCallBack, NULL);
  2658. }
  2659. }
  2660. return rc;
  2661. } //DebugNotify
  2662. /***LP OutPort - Write to an I/O port
  2663. *
  2664. * dwPort - port address
  2665. * dwSize - port size
  2666. * dwData - data to be written
  2667. *
  2668. * EXIT-SUCCESS
  2669. * returns DBGERR_NONE
  2670. * EXIT-FAILURE
  2671. * returns negative error code
  2672. */
  2673. LONG LOCAL OutPort(ULONG dwPort, ULONG dwSize, ULONG dwData)
  2674. {
  2675. LONG rc = DBGERR_NONE;
  2676. PHYSICAL_ADDRESS phyaddr = {0, 0}, XlatedAddr;
  2677. ULONG dwAddrSpace;
  2678. phyaddr.LowPart = dwPort;
  2679. dwAddrSpace = 1;
  2680. if (HalTranslateBusAddress(Internal, 0, phyaddr, &dwAddrSpace, &XlatedAddr))
  2681. {
  2682. dwPort = XlatedAddr.LowPart;
  2683. WriteSystemIO(dwPort, dwSize, dwData);
  2684. }
  2685. else
  2686. {
  2687. DBG_ERROR(("failed to translate port address"));
  2688. rc = DBGERR_CMD_FAILED;
  2689. }
  2690. return rc;
  2691. } //OutPort
  2692. /***LP DebugOutPort - Port output
  2693. *
  2694. * ENTRY
  2695. * pszArg -> argument string
  2696. * dwSize - port size
  2697. *
  2698. * EXIT-SUCCESS
  2699. * returns DBGERR_NONE
  2700. * EXIT-FAILURE
  2701. * returns negative error code
  2702. */
  2703. LONG LOCAL DebugOutPort(PSZ pszArg, ULONG dwSize)
  2704. {
  2705. LONG rc = DBGERR_NONE;
  2706. static int icArgs = 0;
  2707. static ULONG dwPort = 0;
  2708. if (pszArg != NULL)
  2709. {
  2710. ULONG_PTR uipData;
  2711. icArgs++;
  2712. if ((icArgs > 2) || !IsNumber(pszArg, 16, &uipData))
  2713. {
  2714. DBG_ERROR(("invalid outport command"));
  2715. rc = DBGERR_INVALID_CMD;
  2716. }
  2717. else if (icArgs == 1)
  2718. {
  2719. dwPort = (ULONG)uipData;
  2720. }
  2721. else
  2722. {
  2723. OutPort(dwPort, dwSize, (ULONG)uipData);
  2724. }
  2725. if (rc != DBGERR_NONE)
  2726. icArgs = 0;
  2727. }
  2728. else
  2729. {
  2730. if (icArgs != 2)
  2731. {
  2732. DBG_ERROR(("invalid outport command"));
  2733. rc = DBGERR_INVALID_CMD;
  2734. }
  2735. icArgs = 0;
  2736. }
  2737. return rc;
  2738. } //DebugOutPort
  2739. /***LP DebugO - Byte port output
  2740. *
  2741. * ENTRY
  2742. * pArg -> argument type entry
  2743. * pszArg -> argument string
  2744. * dwArgNum - argument number
  2745. * dwNonSWArgs - number of non-switch arguments
  2746. *
  2747. * EXIT-SUCCESS
  2748. * returns DBGERR_NONE
  2749. * EXIT-FAILURE
  2750. * returns negative error code
  2751. */
  2752. LONG LOCAL DebugO(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum, ULONG dwNonSWArgs)
  2753. {
  2754. LONG rc;
  2755. DEREF(pArg);
  2756. DEREF(dwArgNum);
  2757. DEREF(dwNonSWArgs);
  2758. rc = DebugOutPort(pszArg, sizeof(UCHAR));
  2759. return rc;
  2760. } //DebugO
  2761. /***LP DebugOW - Word port output
  2762. *
  2763. * ENTRY
  2764. * pArg -> argument type entry
  2765. * pszArg -> argument string
  2766. * dwArgNum - argument number
  2767. * dwNonSWArgs - number of non-switch arguments
  2768. *
  2769. * EXIT-SUCCESS
  2770. * returns DBGERR_NONE
  2771. * EXIT-FAILURE
  2772. * returns negative error code
  2773. */
  2774. LONG LOCAL DebugOW(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum, ULONG dwNonSWArgs)
  2775. {
  2776. LONG rc;
  2777. DEREF(pArg);
  2778. DEREF(dwArgNum);
  2779. DEREF(dwNonSWArgs);
  2780. rc = DebugOutPort(pszArg, sizeof(USHORT));
  2781. return rc;
  2782. } //DebugOW
  2783. /***LP DebugOD - DWord port output
  2784. *
  2785. * ENTRY
  2786. * pArg -> argument type entry
  2787. * pszArg -> argument string
  2788. * dwArgNum - argument number
  2789. * dwNonSWArgs - number of non-switch arguments
  2790. *
  2791. * EXIT-SUCCESS
  2792. * returns DBGERR_NONE
  2793. * EXIT-FAILURE
  2794. * returns negative error code
  2795. */
  2796. LONG LOCAL DebugOD(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum, ULONG dwNonSWArgs)
  2797. {
  2798. LONG rc;
  2799. DEREF(pArg);
  2800. DEREF(dwArgNum);
  2801. DEREF(dwNonSWArgs);
  2802. rc = DebugOutPort(pszArg, sizeof(ULONG));
  2803. return rc;
  2804. } //DebugOD
  2805. /***LP PrintSymbol - Print the nearest symbol of a given address
  2806. *
  2807. * ENTRY
  2808. * pb - address
  2809. *
  2810. * EXIT
  2811. * None
  2812. */
  2813. VOID LOCAL PrintSymbol(PUCHAR pb)
  2814. {
  2815. PNSOBJ pns;
  2816. ULONG dwOffset;
  2817. if (FindObjSymbol(pb, &pns, &dwOffset))
  2818. {
  2819. PRINTF("%x: %s", pb, GetObjectPath(pns));
  2820. if (dwOffset != 0)
  2821. PRINTF(" + %x\n", dwOffset);
  2822. else
  2823. PRINTF("\n");
  2824. }
  2825. else
  2826. {
  2827. PRINTF("%x: no symbols found", pb);
  2828. }
  2829. } //PrintSymbol
  2830. /***LP DebugStep - Trace and step over an AML instruction
  2831. *
  2832. * ENTRY
  2833. * pArg -> argument type entry
  2834. * pszArg -> argument string
  2835. * dwArgNum - argument number
  2836. * dwNonSWArgs - number of non-switch arguments
  2837. *
  2838. * EXIT-SUCCESS
  2839. * returns DBGERR_NONE
  2840. * EXIT-FAILURE
  2841. * returns negative error code
  2842. */
  2843. LONG LOCAL DebugStep(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  2844. ULONG dwNonSWArgs)
  2845. {
  2846. LONG rc = DBGERR_NONE;
  2847. DEREF(pArg);
  2848. DEREF(dwArgNum);
  2849. DEREF(dwNonSWArgs);
  2850. if (pszArg == NULL)
  2851. {
  2852. gDebugger.dwfDebugger |= DBGF_STEP_OVER;
  2853. rc = DBGERR_QUIT;
  2854. }
  2855. else
  2856. {
  2857. DBG_ERROR(("invalid step command"));
  2858. rc = DBGERR_INVALID_CMD;
  2859. }
  2860. return rc;
  2861. } //DebugStep
  2862. /***LP DumpContext - Dump context
  2863. *
  2864. * ENTRY
  2865. * pctxt -> CTXT
  2866. *
  2867. * EXIT
  2868. * None
  2869. */
  2870. VOID LOCAL DumpContext(PCTXT pctxt)
  2871. {
  2872. PNSOBJ pns = NULL;
  2873. ULONG dwOffset = 0;
  2874. int i;
  2875. PLIST plist, plistNext;
  2876. PRESOURCE pres;
  2877. PUCHAR pbBegin = NULL, pbEnd = NULL;
  2878. #ifdef DEBUG
  2879. PRINTF("\nContext=%08x%c, Queue=%08x, ResList=%08x\n",
  2880. pctxt, (pctxt == gReadyQueue.pctxtCurrent)? '*': ' ',
  2881. pctxt->pplistCtxtQueue, pctxt->plistResources);
  2882. PRINTF("ThreadID=%08x, Flags=%08x\n",
  2883. (pctxt == gReadyQueue.pctxtCurrent)? gReadyQueue.pkthCurrent: 0,
  2884. pctxt->dwfCtxt);
  2885. PRINTF("StackTop=%08x, UsedStackSize=%d bytes, FreeStackSize=%d bytes\n",
  2886. pctxt->LocalHeap.pbHeapEnd,
  2887. pctxt->pbCtxtEnd - pctxt->LocalHeap.pbHeapEnd,
  2888. pctxt->LocalHeap.pbHeapEnd - pctxt->LocalHeap.pbHeapTop);
  2889. PRINTF("LocalHeap=%08x, CurrentHeap=%08x, UsedHeapSize=%d bytes\n",
  2890. &pctxt->LocalHeap, pctxt->pheapCurrent,
  2891. pctxt->LocalHeap.pbHeapTop - (PUCHAR)&pctxt->LocalHeap);
  2892. PRINTF("Object=%s, Scope=%s, ObjectOwner=%x, SyncLevel=%x\n",
  2893. pctxt->pnsObj? GetObjectPath(pctxt->pnsObj): "<none>",
  2894. pctxt->pnsScope? GetObjectPath(pctxt->pnsScope): "<none>",
  2895. pctxt->powner, pctxt->dwSyncLevel);
  2896. PRINTF("AsyncCallBack=%x, CallBackData=%x, CallBackContext=%x\n",
  2897. pctxt->pfnAsyncCallBack, pctxt->pdataCallBack,
  2898. pctxt->pvContext);
  2899. #endif
  2900. if (pctxt->pcall != NULL)
  2901. {
  2902. PRINTF("\nMethodObject=%s\n",
  2903. pctxt->pcall->pnsMethod?
  2904. GetObjectPath(pctxt->pcall->pnsMethod): "<none>");
  2905. for (i = 0; i < pctxt->pcall->icArgs; ++i)
  2906. {
  2907. PRINTF("%08x: Arg%d=", &pctxt->pcall->pdataArgs[i], i);
  2908. DumpObject(&pctxt->pcall->pdataArgs[i], NULL, 0);
  2909. }
  2910. for (i = 0; i < MAX_NUM_LOCALS; ++i)
  2911. {
  2912. PRINTF("%08x: Local%d=", &pctxt->pcall->Locals[i], i);
  2913. DumpObject(&pctxt->pcall->Locals[i], NULL, 0);
  2914. }
  2915. }
  2916. PRINTF("%08x: RetObj=", &pctxt->Result);
  2917. DumpObject(&pctxt->Result, NULL, 0);
  2918. if (pctxt->plistResources != NULL)
  2919. {
  2920. PRINTF("\nResources Owned:\n");
  2921. for (plist = pctxt->plistResources; plist != NULL; plist = plistNext)
  2922. {
  2923. plistNext = (plist->plistNext != pctxt->plistResources)?
  2924. plist->plistNext: NULL;
  2925. pres = CONTAINING_RECORD(plist, RESOURCE, list);
  2926. ASSERT(pctxt == pres->pctxtOwner);
  2927. PRINTF(" ResType=%s, ResObj=%x\n",
  2928. pres->dwResType == RESTYPE_MUTEX? "Mutex": "Unknown",
  2929. pres->pvResObj);
  2930. }
  2931. }
  2932. PRINTF("\nNext AML Pointer: %08x", pctxt->pbOp);
  2933. if (FindObjSymbol(pctxt->pbOp, &pns, &dwOffset))
  2934. {
  2935. PRINTF(" [%s", GetObjectPath(pns));
  2936. if (dwOffset != 0)
  2937. PRINTF(" + %x]", dwOffset);
  2938. else
  2939. PRINTF("]");
  2940. }
  2941. pbBegin = pctxt->pbOp;
  2942. gpnsCurUnAsmScope = NULL;
  2943. if (pns != NULL)
  2944. {
  2945. pbEnd = pns->ObjData.pbDataBuff + pns->ObjData.dwDataLen;
  2946. gpnsCurUnAsmScope = pns;
  2947. }
  2948. else if ((pbBegin >= gDebugger.pbBlkBegin) &&
  2949. (pbBegin < gDebugger.pbBlkEnd))
  2950. {
  2951. pbEnd = gDebugger.pbBlkEnd;
  2952. }
  2953. if (pbEnd != NULL)
  2954. {
  2955. UnAsmScope(&pbBegin, pbEnd, 0, 1);
  2956. PRINTF("\n");
  2957. }
  2958. PRINTF("\n");
  2959. } //DumpContext
  2960. /***LP DebugDumpContext - Dump debugger context
  2961. *
  2962. * ENTRY
  2963. * pArg -> argument type entry
  2964. * pszArg -> argument string
  2965. * dwArgNum - argument number
  2966. * dwNonSWArgs - number of non-switch arguments
  2967. *
  2968. * EXIT-SUCCESS
  2969. * returns DBGERR_NONE
  2970. * EXIT-FAILURE
  2971. * returns negative error code
  2972. */
  2973. LONG LOCAL DebugDumpContext(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  2974. ULONG dwNonSWArgs)
  2975. {
  2976. LONG rc = DBGERR_NONE;
  2977. static BOOLEAN fProcessed = FALSE;
  2978. DEREF(pArg);
  2979. DEREF(dwArgNum);
  2980. DEREF(dwNonSWArgs);
  2981. if (pszArg != NULL)
  2982. {
  2983. PCTXT pctxt;
  2984. if ((rc = DebugExpr(pszArg, (PULONG_PTR)&pctxt, NULL, NULL, NULL)) ==
  2985. DBGERR_NONE)
  2986. {
  2987. if (pctxt->dwSig == SIG_CTXT)
  2988. {
  2989. DumpContext(pctxt);
  2990. fProcessed = TRUE;
  2991. }
  2992. else
  2993. {
  2994. DBG_ERROR(("invalid context address - %x", pctxt));
  2995. rc = DBGERR_CMD_FAILED;
  2996. }
  2997. }
  2998. }
  2999. else
  3000. {
  3001. if (fProcessed)
  3002. {
  3003. fProcessed = FALSE;
  3004. }
  3005. else if (gReadyQueue.pctxtCurrent == NULL)
  3006. {
  3007. DBG_ERROR(("no current context"));
  3008. rc = DBGERR_CMD_FAILED;
  3009. }
  3010. else
  3011. {
  3012. DumpContext(gReadyQueue.pctxtCurrent);
  3013. }
  3014. }
  3015. return rc;
  3016. } //DebugDumpContext
  3017. /***LP DebugSet - Set debugger options
  3018. *
  3019. * ENTRY
  3020. * pArg -> argument type entry
  3021. * pszArg -> argument string
  3022. * dwArgNum - argument number
  3023. * dwNonSWArgs - number of non-switch arguments
  3024. *
  3025. * EXIT-SUCCESS
  3026. * returns DBGERR_NONE
  3027. * EXIT-FAILURE
  3028. * returns negative error code
  3029. */
  3030. LONG LOCAL DebugSet(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  3031. ULONG dwNonSWArgs)
  3032. {
  3033. LONG rc = DBGERR_NONE;
  3034. DEREF(pArg);
  3035. DEREF(dwNonSWArgs);
  3036. if ((pszArg == NULL) && (dwArgNum == 0))
  3037. {
  3038. PRINTF("AMLTrace =%s\n",
  3039. (gDebugger.dwfDebugger & DBGF_AMLTRACE_ON)? "on": "off");
  3040. PRINTF("AMLDebugSpew =%s\n",
  3041. (gDebugger.dwfDebugger & DBGF_DEBUG_SPEW_ON)? "on": "off");
  3042. PRINTF("LoadDDBBreak =%s\n",
  3043. (gdwfAMLIInit & AMLIIF_LOADDDB_BREAK)? "on": "off");
  3044. PRINTF("ErrorBreak =%s\n",
  3045. (gDebugger.dwfDebugger & DBGF_ERRBREAK_ON)? "on": "off");
  3046. PRINTF("VerboseMode =%s\n",
  3047. (gDebugger.dwfDebugger & DBGF_VERBOSE_ON)? "on": "off");
  3048. PRINTF("LogEvent =%s\n",
  3049. (gDebugger.dwfDebugger & DBGF_LOGEVENT_ON)? "on": "off");
  3050. PRINTF("LogSize =%d\n", gDebugger.dwLogSize);
  3051. }
  3052. else
  3053. {
  3054. if(gDebugger.dwfDebugger & DBGF_DEBUG_SPEW_ON)
  3055. {
  3056. if(!CheckAndEnableDebugSpew(TRUE))
  3057. gDebugger.dwfDebugger &= ~DBGF_DEBUG_SPEW_ON;
  3058. }
  3059. else if(gDebugger.dwfDebugger & ~DBGF_DEBUG_SPEW_ON)
  3060. {
  3061. if(!CheckAndEnableDebugSpew(FALSE))
  3062. gDebugger.dwfDebugger |= DBGF_DEBUG_SPEW_ON;
  3063. }
  3064. }
  3065. return rc;
  3066. } //DebugSet
  3067. /***LP DebugSetLogSize - Set EventLog size
  3068. *
  3069. * ENTRY
  3070. * pArg -> argument type entry
  3071. * pszArg -> argument string
  3072. * dwArgNum - argument number
  3073. * dwNonSWArgs - number of non-switch arguments
  3074. *
  3075. * EXIT-SUCCESS
  3076. * returns DBGERR_NONE
  3077. * EXIT-FAILURE
  3078. * returns negative error code
  3079. */
  3080. LONG LOCAL DebugSetLogSize(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  3081. ULONG dwNonSWArgs)
  3082. {
  3083. LONG rc = DBGERR_NONE;
  3084. DEREF(pArg);
  3085. DEREF(pszArg);
  3086. DEREF(dwArgNum);
  3087. DEREF(dwNonSWArgs);
  3088. if (!SetLogSize(dwCmdArg))
  3089. {
  3090. DBG_ERROR(("failed to set EventLog size to %d", dwCmdArg));
  3091. rc = DBGERR_CMD_FAILED;
  3092. }
  3093. return rc;
  3094. } //DebugSetLogSize
  3095. /***LP SetLogSize - Set EventLog size
  3096. *
  3097. * ENTRY
  3098. * dwLogSize - EventLog size
  3099. *
  3100. * EXIT-SUCCESS
  3101. * returns TRUE
  3102. * EXIT-FAILURE
  3103. * returns FALSE
  3104. */
  3105. BOOLEAN LOCAL SetLogSize(ULONG dwLogSize)
  3106. {
  3107. BOOLEAN rc = FALSE;
  3108. if (gDebugger.pEventLog != NULL)
  3109. {
  3110. MFREE(gDebugger.pEventLog);
  3111. gDebugger.pEventLog = NULL;
  3112. gDebugger.dwLogSize = 0;
  3113. gDebugger.dwLogIndex = 0;
  3114. }
  3115. if ((gDebugger.pEventLog = MALLOC_LOCKED(sizeof(EVENTLOG)*dwLogSize,
  3116. 'GOLE')) != NULL)
  3117. {
  3118. gDebugger.dwLogSize = dwLogSize;
  3119. gDebugger.dwLogIndex = 0;
  3120. MEMZERO(gDebugger.pEventLog, sizeof(EVENTLOG)*dwLogSize);
  3121. rc = TRUE;
  3122. }
  3123. return rc;
  3124. } //SetLogSize
  3125. /***LP DebugTrace - Single-step an AML instruction
  3126. *
  3127. * ENTRY
  3128. * pArg -> argument type entry
  3129. * pszArg -> argument string
  3130. * dwArgNum - argument number
  3131. * dwNonSWArgs - number of non-switch arguments
  3132. *
  3133. * EXIT-SUCCESS
  3134. * returns DBGERR_NONE
  3135. * EXIT-FAILURE
  3136. * returns negative error code
  3137. */
  3138. LONG LOCAL DebugTrace(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  3139. ULONG dwNonSWArgs)
  3140. {
  3141. LONG rc;
  3142. DEREF(pArg);
  3143. DEREF(dwArgNum);
  3144. DEREF(dwNonSWArgs);
  3145. if (pszArg == NULL)
  3146. {
  3147. gDebugger.dwfDebugger |= DBGF_SINGLE_STEP;
  3148. rc = DBGERR_QUIT;
  3149. }
  3150. else
  3151. {
  3152. DBG_ERROR(("invalid trace command"));
  3153. rc = DBGERR_INVALID_CMD;
  3154. }
  3155. return rc;
  3156. } //DebugTrace
  3157. /***LP DebugUnAsm - Unassemble AML code
  3158. *
  3159. * ENTRY
  3160. * pArg -> argument type entry
  3161. * pszArg -> argument string
  3162. * dwArgNum - argument number
  3163. * dwNonSWArgs - number of non-switch arguments
  3164. *
  3165. * EXIT-SUCCESS
  3166. * returns DBGERR_NONE
  3167. * EXIT-FAILURE
  3168. * returns negative error code
  3169. */
  3170. LONG LOCAL DebugUnAsm(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  3171. ULONG dwNonSWArgs)
  3172. {
  3173. LONG rc = DBGERR_NONE;
  3174. static BOOLEAN fParsedAddr = FALSE;
  3175. PNSOBJ pns = NULL;
  3176. DEREF(pArg);
  3177. DEREF(dwArgNum);
  3178. //
  3179. // User specified name space path or memory address
  3180. //
  3181. if (pszArg != NULL)
  3182. {
  3183. if (fParsedAddr && (dwNonSWArgs == 1))
  3184. {
  3185. //
  3186. // Impossible, it must be abort value from last time, clear it.
  3187. //
  3188. fParsedAddr = FALSE;
  3189. }
  3190. if (!fParsedAddr)
  3191. {
  3192. PUCHAR pbAddr;
  3193. gpnsCurUnAsmScope = NULL;
  3194. if ((rc = DebugExpr(pszArg, (PULONG_PTR)&pbAddr, NULL, &pns, NULL))
  3195. == DBGERR_NONE)
  3196. {
  3197. gDebugger.pbUnAsm = pbAddr;
  3198. gDebugger.pbUnAsmEnd = NULL;
  3199. fParsedAddr = TRUE;
  3200. if (pns != NULL)
  3201. {
  3202. gDebugger.pbUnAsmEnd = pns->ObjData.pbDataBuff +
  3203. pns->ObjData.dwDataLen;
  3204. gpnsCurUnAsmScope = pns;
  3205. }
  3206. }
  3207. }
  3208. else
  3209. {
  3210. DBG_ERROR(("invalid unassemble command"));
  3211. rc = DBGERR_INVALID_CMD;
  3212. }
  3213. }
  3214. else
  3215. {
  3216. if (!fParsedAddr && (gDebugger.pbUnAsm == NULL) &&
  3217. (gReadyQueue.pctxtCurrent != NULL))
  3218. {
  3219. ULONG dwOffset;
  3220. gDebugger.pbUnAsm = gReadyQueue.pctxtCurrent->pbOp;
  3221. gDebugger.pbUnAsmEnd = NULL;
  3222. gpnsCurUnAsmScope = NULL;
  3223. if (FindObjSymbol(gDebugger.pbUnAsm, &pns, &dwOffset))
  3224. {
  3225. gDebugger.pbUnAsmEnd = pns->ObjData.pbDataBuff +
  3226. pns->ObjData.dwDataLen;
  3227. gpnsCurUnAsmScope = pns;
  3228. }
  3229. }
  3230. if (gDebugger.pbUnAsmEnd == NULL)
  3231. {
  3232. if ((gDebugger.pbUnAsm >= gDebugger.pbBlkBegin) &&
  3233. (gDebugger.pbUnAsm < gDebugger.pbBlkEnd))
  3234. {
  3235. gDebugger.pbUnAsmEnd = gDebugger.pbBlkEnd;
  3236. }
  3237. else
  3238. {
  3239. ULONG dwLen;
  3240. //
  3241. // don't know code len, start with 64K
  3242. //
  3243. for (dwLen = 64*1024; dwLen > 0; dwLen >>= 1)
  3244. {
  3245. if (ASSERTRANGE(gDebugger.pbUnAsm, dwLen))
  3246. {
  3247. gDebugger.pbUnAsmEnd = gDebugger.pbUnAsm + dwLen;
  3248. break;
  3249. }
  3250. }
  3251. if (dwLen == 0)
  3252. {
  3253. DBG_ERROR(("invalid address %x", gDebugger.pbUnAsm));
  3254. rc = DBGERR_INVALID_CMD;
  3255. }
  3256. }
  3257. }
  3258. if ((rc == DBGERR_NONE) && (gDebugger.pbUnAsm != NULL) &&
  3259. (gDebugger.pbUnAsmEnd > gDebugger.pbUnAsm))
  3260. {
  3261. rc = UnAsmScope(&gDebugger.pbUnAsm, gDebugger.pbUnAsmEnd,
  3262. fParsedAddr? 0: -1, 0);
  3263. PRINTF("\n");
  3264. if (rc == UNASMERR_ABORT)
  3265. {
  3266. rc = DBGERR_NONE;
  3267. }
  3268. }
  3269. else
  3270. {
  3271. gDebugger.pbUnAsm = gDebugger.pbUnAsmEnd = NULL;
  3272. }
  3273. fParsedAddr = FALSE;
  3274. }
  3275. return rc;
  3276. } //DebugUnAsm
  3277. BOOLEAN fRunningMethod = FALSE;
  3278. /***LP DebugRunMethod - Run Method
  3279. *
  3280. * ENTRY
  3281. * pArg -> argument type entry
  3282. * pszArg -> argument string
  3283. * dwArgNum - argument number
  3284. * dwNonSWArgs - number of non-switch arguments
  3285. *
  3286. * EXIT-SUCCESS
  3287. * returns DBGERR_NONE
  3288. * EXIT-FAILURE
  3289. * returns negative error code
  3290. */
  3291. LONG LOCAL DebugRunMethod(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  3292. ULONG dwNonSWArgs)
  3293. {
  3294. LONG rc = DBGERR_NONE;
  3295. static int icArgs = -1;
  3296. static PNSOBJ pns = NULL;
  3297. static OBJDATA Args[MAX_NUM_ARGS] = {0};
  3298. static OBJDATA Result;
  3299. DEREF(pArg);
  3300. DEREF(dwArgNum);
  3301. DEREF(dwNonSWArgs);
  3302. if (fRunningMethod)
  3303. {
  3304. DBG_ERROR(("Cannot run method while previous method is still pending"));
  3305. rc = DBGERR_CMD_FAILED;
  3306. }
  3307. else if (pszArg != NULL)
  3308. {
  3309. if (icArgs == -1)
  3310. {
  3311. PUCHAR pbAddr;
  3312. if ((rc = DebugExpr(pszArg, (PULONG_PTR)&pbAddr, NULL, &pns, NULL))
  3313. == DBGERR_NONE)
  3314. {
  3315. if (pns != NULL)
  3316. {
  3317. pns = GetBaseObject(pns);
  3318. icArgs = 0;
  3319. }
  3320. else
  3321. {
  3322. DBG_ERROR(("invalid method or method not found"));
  3323. rc = DBGERR_CMD_FAILED;
  3324. }
  3325. }
  3326. }
  3327. else if (icArgs < MAX_NUM_ARGS)
  3328. {
  3329. MEMZERO(&Args[icArgs], sizeof(OBJDATA));
  3330. if (IsNumber(pszArg, 0, &Args[icArgs].uipDataValue))
  3331. {
  3332. Args[icArgs].dwDataType = OBJTYPE_INTDATA;
  3333. icArgs++;
  3334. }
  3335. else
  3336. {
  3337. DBG_ERROR(("invalid argument %s (can only be integer)",
  3338. pszArg));
  3339. rc = DBGERR_INVALID_CMD;
  3340. }
  3341. }
  3342. else
  3343. {
  3344. DBG_ERROR(("too many arguments"));
  3345. rc = DBGERR_INVALID_CMD;
  3346. }
  3347. }
  3348. else if (icArgs >= 0)
  3349. {
  3350. NTSTATUS rcAMLI;
  3351. MEMZERO(&Result, sizeof(OBJDATA));
  3352. fRunningMethod = TRUE;
  3353. if ((rcAMLI = AsyncEvalObject(pns, &Result, icArgs, Args,
  3354. RunMethodCallBack, NULL, TRUE)) !=
  3355. AMLISTA_PENDING)
  3356. {
  3357. RunMethodCallBack(pns, rcAMLI, &Result, NULL);
  3358. if (rcAMLI != STATUS_SUCCESS)
  3359. {
  3360. rc = DBGERR_CMD_FAILED;
  3361. }
  3362. }
  3363. else
  3364. {
  3365. PRINTF("\n%s returned PENDING\n", GetObjectPath(pns));
  3366. }
  3367. icArgs = -1;
  3368. }
  3369. else
  3370. {
  3371. DBG_ERROR(("invalid run command"));
  3372. rc = DBGERR_CMD_FAILED;
  3373. }
  3374. if (rc != DBGERR_NONE)
  3375. {
  3376. icArgs = -1;
  3377. }
  3378. return rc;
  3379. } //DebugRunMethod
  3380. /***LP RunMethodCallBack - RunMethod completion callback
  3381. *
  3382. * ENTRY
  3383. * pns -> method object
  3384. * rc - execution status code
  3385. * pdata -> result data
  3386. * pvContext -> context data
  3387. *
  3388. * EXIT
  3389. * None
  3390. */
  3391. VOID EXPORT RunMethodCallBack(PNSOBJ pns, NTSTATUS rc, POBJDATA pdata,
  3392. PVOID pvContext)
  3393. {
  3394. DEREF(pvContext);
  3395. if (rc == STATUS_SUCCESS)
  3396. {
  3397. PRINTF("\n%s completed successfully with object data:\n",
  3398. GetObjectPath(pns));
  3399. DumpObject(pdata, NULL, 0);
  3400. }
  3401. else
  3402. {
  3403. PSZ pszErr;
  3404. AMLIGetLastError(&pszErr);
  3405. PRINTF("\n%s failed with the following error:\n%s\n",
  3406. GetObjectPath(pns), pszErr);
  3407. }
  3408. fRunningMethod = FALSE;
  3409. } //RunMethodCallBack
  3410. /***LP AddObjSymbol - Add object to symbol table
  3411. *
  3412. * ENTRY
  3413. * pbOp -> code address
  3414. * pnsObj -> object
  3415. *
  3416. * EXIT
  3417. * None
  3418. */
  3419. VOID LOCAL AddObjSymbol(PUCHAR pbOp, PNSOBJ pnsObj)
  3420. {
  3421. POBJSYM pos, p;
  3422. if ((pos = NEWSYOBJ(sizeof(OBJSYM))) == NULL)
  3423. {
  3424. AMLI_ERROR(("AddObjSymbol: failed to allocate symbol buffer"));
  3425. }
  3426. else
  3427. {
  3428. MEMZERO(pos, sizeof(OBJSYM));
  3429. pos->pbOp = pbOp;
  3430. pos->pnsObj = pnsObj;
  3431. if (gDebugger.posSymbolList == NULL)
  3432. {
  3433. gDebugger.posSymbolList = pos;
  3434. }
  3435. else if (pbOp < gDebugger.posSymbolList->pbOp)
  3436. {
  3437. pos->posNext = gDebugger.posSymbolList;
  3438. gDebugger.posSymbolList->posPrev = pos;
  3439. gDebugger.posSymbolList = pos;
  3440. }
  3441. else
  3442. {
  3443. for (p = gDebugger.posSymbolList; p != NULL; p = p->posNext)
  3444. {
  3445. if (pbOp < p->pbOp)
  3446. {
  3447. pos->posNext = p;
  3448. pos->posPrev = p->posPrev;
  3449. p->posPrev->posNext = pos;
  3450. p->posPrev = pos;
  3451. break;
  3452. }
  3453. else if (p->posNext == NULL)
  3454. {
  3455. pos->posPrev = p;
  3456. p->posNext = pos;
  3457. break;
  3458. }
  3459. }
  3460. }
  3461. }
  3462. } //AddObjSymbol
  3463. /***LP FreeSymList - Free all object symbols
  3464. *
  3465. * ENTRY
  3466. * None
  3467. *
  3468. * EXIT
  3469. * None
  3470. */
  3471. VOID LOCAL FreeSymList(VOID)
  3472. {
  3473. POBJSYM pos, posNext;
  3474. for (pos = gDebugger.posSymbolList; pos != NULL; pos = posNext)
  3475. {
  3476. posNext = pos->posNext;
  3477. FREESYOBJ(pos);
  3478. }
  3479. } //FreeSymList
  3480. /***LP FindObjSymbol - Find nearest object with given address
  3481. *
  3482. * ENTRY
  3483. * pbOp - address
  3484. * ppns -> to hold the nearest object
  3485. * pdwOffset - to hold offset from the nearest object
  3486. *
  3487. * EXIT-SUCCESS
  3488. * returns TRUE - found a nearest object
  3489. * EXIT-FAILURE
  3490. * returns FALSE - cannot found nearest object
  3491. */
  3492. BOOLEAN LOCAL FindObjSymbol(PUCHAR pbOp, PPNSOBJ ppns, PULONG pdwOffset)
  3493. {
  3494. BOOLEAN rc = FALSE;
  3495. POBJSYM pos;
  3496. for (pos = gDebugger.posSymbolList; pos != NULL; pos = pos->posNext)
  3497. {
  3498. if (pbOp <= pos->pbOp)
  3499. {
  3500. if ((pbOp < pos->pbOp) && (pos->posPrev != NULL))
  3501. pos = pos->posPrev;
  3502. if (pbOp >= pos->pbOp)
  3503. {
  3504. *ppns = pos->pnsObj;
  3505. *pdwOffset = (ULONG)(pbOp - pos->pbOp);
  3506. rc = TRUE;
  3507. }
  3508. break;
  3509. }
  3510. }
  3511. return rc;
  3512. } //FindObjSymbol
  3513. /***LP CheckBP - Check given address is in the breakpoint list
  3514. *
  3515. * ENTRY
  3516. * pbOp - address
  3517. *
  3518. * EXIT-SUCCESS
  3519. * returns breakpoint number
  3520. * EXIT-FAILURE
  3521. * returns -1
  3522. */
  3523. int LOCAL CheckBP(PUCHAR pbOp)
  3524. {
  3525. int i;
  3526. for (i = 0; i < MAX_BRK_PTS; ++i)
  3527. {
  3528. if (pbOp == gDebugger.BrkPts[i].pbBrkPt)
  3529. {
  3530. break;
  3531. }
  3532. }
  3533. if ((i == MAX_BRK_PTS) ||
  3534. !(gDebugger.BrkPts[i].dwfBrkPt & BPF_ENABLED))
  3535. {
  3536. i = -1;
  3537. }
  3538. return i;
  3539. } //CheckBP
  3540. /***LP PrintfBuffData - Print buffer data
  3541. *
  3542. * ENTRY
  3543. * pb -> buffer
  3544. * dwLen - length of buffer
  3545. *
  3546. * EXIT
  3547. * None
  3548. */
  3549. VOID LOCAL PrintBuffData(PUCHAR pb, ULONG dwLen)
  3550. {
  3551. TRACENAME("PRINTBUFFDATA")
  3552. int i, j;
  3553. ENTER(4, ("PrintBuffData(pb=%x,Len=%d)\n", pb, dwLen));
  3554. PRINTF("{");
  3555. for (i = j = 0; i < (int)dwLen; ++i)
  3556. {
  3557. if (j == 0)
  3558. PRINTF("\n\t0x%02x", pb[i]);
  3559. else
  3560. PRINTF(",0x%02x", pb[i]);
  3561. j++;
  3562. if (j >= 14)
  3563. j = 0;
  3564. }
  3565. PRINTF("}");
  3566. EXIT(4, ("PrintBuffData!\n"));
  3567. } //PrintBuffData
  3568. /***LP PrintIndent - Print indentation
  3569. *
  3570. * ENTRY
  3571. * pctxt -> CTXT
  3572. *
  3573. * EXIT
  3574. * None
  3575. */
  3576. VOID LOCAL PrintIndent(PCTXT pctxt)
  3577. {
  3578. TRACENAME("PRINTINDENT")
  3579. int i;
  3580. ENTER(4, ("PrintIndent(pctxt=%x,pbOp=%x)\n", pctxt, pctxt->pbOp));
  3581. PRINTF("\n%08x: ", pctxt->pbOp);
  3582. for (i = 0; i < gDebugger.iPrintLevel; ++i)
  3583. {
  3584. PRINTF("| ");
  3585. }
  3586. EXIT(4, ("PrintIndent!\n"));
  3587. } //PrintIndent
  3588. /***LP PrintObject - Print object content
  3589. *
  3590. * ENTRY
  3591. * pdata -> object
  3592. *
  3593. * EXIT
  3594. * None
  3595. */
  3596. VOID LOCAL PrintObject(POBJDATA pdata)
  3597. {
  3598. TRACENAME("PRINTOBJECT")
  3599. int i;
  3600. ENTER(4, ("PrintObject(pdata=%x)\n", pdata));
  3601. switch (pdata->dwDataType)
  3602. {
  3603. case OBJTYPE_INTDATA:
  3604. PRINTF("0x%x", pdata->uipDataValue);
  3605. break;
  3606. case OBJTYPE_STRDATA:
  3607. PRINTF("\"%s\"", pdata->pbDataBuff);
  3608. break;
  3609. case OBJTYPE_BUFFDATA:
  3610. PRINTF("Buffer(0x%x)", pdata->dwDataLen);
  3611. PrintBuffData(pdata->pbDataBuff, pdata->dwDataLen);
  3612. break;
  3613. case OBJTYPE_PKGDATA:
  3614. PRINTF("Package(%d){",
  3615. ((PPACKAGEOBJ)pdata->pbDataBuff)->dwcElements);
  3616. for (i = 0;
  3617. i < (int)((PPACKAGEOBJ)pdata->pbDataBuff)->dwcElements;
  3618. ++i)
  3619. {
  3620. PRINTF("\n\t");
  3621. PrintObject(&((PPACKAGEOBJ)pdata->pbDataBuff)->adata[i]);
  3622. if (i + 1 < (int)((PPACKAGEOBJ)pdata->pbDataBuff)->dwcElements)
  3623. PRINTF(",");
  3624. }
  3625. PRINTF("}");
  3626. break;
  3627. default:
  3628. PRINTF("<Obj=%x,Type=%s,Value=0x%x,Buff=%x,Len=%d>",
  3629. pdata, GetObjectTypeName(pdata->dwDataType),
  3630. pdata->uipDataValue, pdata->pbDataBuff, pdata->dwDataLen);
  3631. }
  3632. EXIT(4, ("PrintObject!\n"));
  3633. } //PrintObject
  3634. /***LP LogEvent - Log an event in the log buffer
  3635. *
  3636. * ENTRY
  3637. * dwEvent - event type
  3638. * uipData1 - log data 1
  3639. * uipData2 - log data 2
  3640. * uipData3 - log data 3
  3641. * uipData4 - log data 4
  3642. * uipData5 - log data 5
  3643. * uipData6 - log data 6
  3644. * uipData7 - log data 7
  3645. *
  3646. * EXIT
  3647. * None
  3648. */
  3649. VOID LOCAL LogEvent(ULONG dwEvent, ULONG_PTR uipData1, ULONG_PTR uipData2,
  3650. ULONG_PTR uipData3, ULONG_PTR uipData4, ULONG_PTR uipData5,
  3651. ULONG_PTR uipData6, ULONG_PTR uipData7)
  3652. {
  3653. if ((gDebugger.dwfDebugger & DBGF_LOGEVENT_ON) &&
  3654. (gDebugger.pEventLog != NULL))
  3655. {
  3656. ULONG i = gDebugger.dwLogIndex;
  3657. gDebugger.pEventLog[i].ullTime = KeQueryInterruptTime();
  3658. gDebugger.pEventLog[i].dwEvent = dwEvent;
  3659. gDebugger.pEventLog[i].uipData1 = uipData1;
  3660. gDebugger.pEventLog[i].uipData2 = uipData2;
  3661. gDebugger.pEventLog[i].uipData3 = uipData3;
  3662. gDebugger.pEventLog[i].uipData4 = uipData4;
  3663. gDebugger.pEventLog[i].uipData5 = uipData5;
  3664. gDebugger.pEventLog[i].uipData6 = uipData6;
  3665. gDebugger.pEventLog[i].uipData7 = uipData7;
  3666. gDebugger.dwLogIndex++;
  3667. if (gDebugger.dwLogIndex >= gDebugger.dwLogSize)
  3668. {
  3669. gDebugger.dwLogIndex = 0;
  3670. }
  3671. }
  3672. } //LogEvent;
  3673. /***LP LogSchedEvent - Log a scheduler event in the log buffer
  3674. *
  3675. * ENTRY
  3676. * dwEvent - event type
  3677. * uipData1 - log data 1
  3678. * uipData2 - log data 2
  3679. * uipData3 - log data 3
  3680. *
  3681. * EXIT
  3682. * None
  3683. */
  3684. VOID LOCAL LogSchedEvent(ULONG dwEvent, ULONG_PTR uipData1, ULONG_PTR uipData2,
  3685. ULONG_PTR uipData3)
  3686. {
  3687. if ((gDebugger.dwfDebugger & DBGF_LOGEVENT_ON) &&
  3688. (gDebugger.pEventLog != NULL))
  3689. {
  3690. ULONG i = gDebugger.dwLogIndex;
  3691. gDebugger.pEventLog[i].ullTime = KeQueryInterruptTime();
  3692. gDebugger.pEventLog[i].dwEvent = dwEvent;
  3693. gDebugger.pEventLog[i].uipData1 = (ULONG_PTR)KeGetCurrentThread();
  3694. gDebugger.pEventLog[i].uipData2 = (ULONG_PTR)gReadyQueue.pkthCurrent;
  3695. gDebugger.pEventLog[i].uipData3 = (ULONG_PTR)gReadyQueue.pctxtCurrent;
  3696. gDebugger.pEventLog[i].uipData4 = (ULONG_PTR)gReadyQueue.dwfCtxtQ;
  3697. gDebugger.pEventLog[i].uipData5 = uipData1;
  3698. gDebugger.pEventLog[i].uipData6 = uipData2;
  3699. gDebugger.pEventLog[i].uipData7 = uipData3;
  3700. gDebugger.dwLogIndex++;
  3701. if (gDebugger.dwLogIndex >= gDebugger.dwLogSize)
  3702. {
  3703. gDebugger.dwLogIndex = 0;
  3704. }
  3705. }
  3706. } //LogSchedEvent
  3707. /***LP LogError - Log error code and message
  3708. *
  3709. * ENTRY
  3710. * rcErr - error code
  3711. *
  3712. * EXIT
  3713. * None
  3714. */
  3715. VOID LOCAL LogError(NTSTATUS rcErr)
  3716. {
  3717. static struct _ErrMsg
  3718. {
  3719. NTSTATUS rcErr;
  3720. PSZ pszMsg;
  3721. } ErrMsgTable[] =
  3722. {
  3723. AMLIERR_NONE, "Success",
  3724. AMLIERR_OUT_OF_MEM, "Failed to allocate memory",
  3725. AMLIERR_INVALID_OPCODE, "Invalid AML Opcode",
  3726. AMLIERR_NAME_TOO_LONG, "Object name is too long",
  3727. AMLIERR_ASSERT_FAILED, "Assertion failure",
  3728. AMLIERR_INVALID_NAME, "Invalid object name",
  3729. AMLIERR_OBJ_NOT_FOUND, "Object not found",
  3730. AMLIERR_OBJ_ALREADY_EXIST, "Object already exist",
  3731. AMLIERR_INDEX_TOO_BIG, "Index is too big",
  3732. AMLIERR_ARG_NOT_EXIST, "Argument does not exist",
  3733. AMLIERR_FATAL, "Fatal error",
  3734. AMLIERR_INVALID_SUPERNAME, "Invalid SuperName",
  3735. AMLIERR_UNEXPECTED_ARGTYPE, "Unexpected argument type",
  3736. AMLIERR_UNEXPECTED_OBJTYPE, "Unexpected object type",
  3737. AMLIERR_UNEXPECTED_TARGETTYPE, "Unexpected target type",
  3738. AMLIERR_INCORRECT_NUMARG, "Incorrect number of arguments",
  3739. AMLIERR_FAILED_ADDR_XLATE, "Failed address translation",
  3740. AMLIERR_INVALID_EVENTTYPE, "Invalid event type",
  3741. AMLIERR_REGHANDLER_FAILED, "Failed to register event handler",
  3742. AMLIERR_HANDLER_EXIST, "Event handler already exist",
  3743. AMLIERR_INVALID_DATA, "Invalid data",
  3744. AMLIERR_INVALID_REGIONSPACE, "Invalid RegionSpace",
  3745. AMLIERR_INVALID_ACCSIZE, "Invalid AccessSize",
  3746. AMLIERR_INVALID_TABLE, "Invalid table",
  3747. AMLIERR_ACQUIREGL_FAILED, "Failed to acquire global lock",
  3748. AMLIERR_ALREADY_INITIALIZED, "AML Interpreter is already initialized",
  3749. AMLIERR_NOT_INITIALIZED, "AML Interpreter is not initialized",
  3750. AMLIERR_MUTEX_INVALID_LEVEL, "Invalid mutex sync level",
  3751. AMLIERR_MUTEX_NOT_OWNED, "Mutex object has no owner",
  3752. AMLIERR_MUTEX_NOT_OWNER, "Mutex object is owned by a different owner",
  3753. AMLIERR_RS_ACCESS, "RegionSpace handler error",
  3754. AMLIERR_STACK_OVERFLOW, "AML Stack overflow",
  3755. AMLIERR_INVALID_BUFFSIZE, "Invalid buffer size",
  3756. AMLIERR_BUFF_TOOSMALL, "Buffer is too small",
  3757. AMLIERR_NOTIFY_FAILED, "Notify handler failed",
  3758. 0, NULL
  3759. };
  3760. int i;
  3761. gDebugger.rcLastError = rcErr;
  3762. for (i = 0; ErrMsgTable[i].pszMsg != NULL; ++i)
  3763. {
  3764. if (rcErr == ErrMsgTable[i].rcErr)
  3765. {
  3766. sprintf(gDebugger.szLastError, MODNAME "_ERROR(%08x): %s",
  3767. rcErr, ErrMsgTable[i].pszMsg);
  3768. break;
  3769. }
  3770. }
  3771. ASSERT(ErrMsgTable[i].pszMsg != NULL);
  3772. } //LogError
  3773. /***LP CatError - Concat to error buffer
  3774. *
  3775. * ENTRY
  3776. * pszFormat -> message format string
  3777. * ... - variable parameters according to format string
  3778. *
  3779. * EXIT
  3780. * None
  3781. */
  3782. VOID LOCAL CatError(PSZ pszFormat, ...)
  3783. {
  3784. va_list marker;
  3785. STRCAT(gDebugger.szLastError, "\n");
  3786. va_start(marker, pszFormat);
  3787. if(_vsnprintf(&gDebugger.szLastError[STRLEN(gDebugger.szLastError)],
  3788. sizeof(gDebugger.szLastError) - STRLEN(gDebugger.szLastError),
  3789. pszFormat, marker) == -1)
  3790. {
  3791. gDebugger.szLastError[sizeof(gDebugger.szLastError) - 1] = '\0';
  3792. }
  3793. va_end(marker);
  3794. ConPrintf(gDebugger.szLastError);
  3795. ConPrintf("\n");
  3796. if (gDebugger.dwfDebugger & DBGF_ERRBREAK_ON)
  3797. {
  3798. AMLIDebugger(FALSE);
  3799. }
  3800. } //CatError
  3801. /***LP ConPrintf - Console printf
  3802. *
  3803. * ENTRY
  3804. * pszFormat -> format string
  3805. * ... - variable parameters according to format string
  3806. *
  3807. * EXIT
  3808. * None
  3809. */
  3810. VOID LOCAL ConPrintf(PSZ pszFormat, ...)
  3811. {
  3812. static char szBuff[1024];
  3813. va_list marker;
  3814. va_start(marker, pszFormat);
  3815. vsprintf(szBuff, pszFormat, marker);
  3816. va_end(marker);
  3817. if (gDebugger.hConMessage.pfnHandler != NULL) {
  3818. ((PFNCM)gDebugger.hConMessage.pfnHandler)(
  3819. szBuff,
  3820. gDebugger.hConMessage.uipParam
  3821. );
  3822. } else {
  3823. _PRINTF(szBuff);
  3824. }
  3825. } //ConPrintf
  3826. /***LP ConPrompt - Console prompted input
  3827. *
  3828. * ENTRY
  3829. * pszPrompt -> prompt string
  3830. * pszBuff -> input buffer
  3831. * dwcbBuff - buffer size
  3832. */
  3833. VOID LOCAL ConPrompt(PSZ pszPrompt, PSZ pszBuff, ULONG dwcbBuff)
  3834. {
  3835. if(gDebugger.dwfDebugger & ~DBGF_DEBUG_SPEW_ON)
  3836. {
  3837. CheckAndEnableDebugSpew(TRUE);
  3838. }
  3839. if (gDebugger.hConPrompt.pfnHandler != NULL)
  3840. {
  3841. ((PFNCP)gDebugger.hConPrompt.pfnHandler)(pszPrompt, pszBuff, dwcbBuff,
  3842. gDebugger.hConPrompt.uipParam);
  3843. }
  3844. else
  3845. {
  3846. DbgPrompt(pszPrompt, pszBuff, dwcbBuff);
  3847. }
  3848. } //ConPrompt
  3849. /***LP CheckAndEnableDebugSpew - Enable debug spew if it is not already turned on.
  3850. *
  3851. * ENTRY
  3852. * BOOLEAN fEnable - Enable iff TRUE.
  3853. *
  3854. * EXIT
  3855. * BOOLEAN - TRUE on success.
  3856. */
  3857. BOOLEAN LOCAL CheckAndEnableDebugSpew(BOOLEAN fEnable)
  3858. {
  3859. BOOLEAN bRet = FALSE;
  3860. if(KeGetCurrentIrql() < DISPATCH_LEVEL)
  3861. {
  3862. if(fEnable)
  3863. {
  3864. gDebugger.dwfDebugger |= DBGF_DEBUG_SPEW_ON;
  3865. DbgSetDebugFilterState( DPFLTR_AMLI_ID, -1, TRUE);
  3866. }
  3867. else
  3868. {
  3869. DbgSetDebugFilterState( DPFLTR_AMLI_ID, -1, FALSE);
  3870. gDebugger.dwfDebugger &= ~DBGF_DEBUG_SPEW_ON;
  3871. }
  3872. bRet = TRUE;
  3873. }
  3874. return bRet;
  3875. }
  3876. #endif //ifdef DEBUGGER
  3877. #ifdef DEBUG
  3878. /***LP DumpMemObjCounts - display memory object counts
  3879. *
  3880. * ENTRY
  3881. * None
  3882. *
  3883. * EXIT
  3884. * None
  3885. */
  3886. VOID LOCAL DumpMemObjCounts(VOID)
  3887. {
  3888. static char szFormat[] = "Number of %s = %d\n";
  3889. PRINTF("CurGlobalHeapSize=%d bytes\n", gdwGlobalHeapSize);
  3890. PRINTF("RefGlobalHeapSize=%d bytes\n", gdwGHeapSnapshot);
  3891. PRINTF("MaxLocalHeapSize =%d bytes\n", gdwLocalHeapMax);
  3892. PRINTF("MaxLocalStackSize=%d bytes\n", gdwLocalStackMax);
  3893. PRINTF(szFormat, "CtxtObj ", gdwcCTObjs);
  3894. PRINTF(szFormat, "HeapObj ", gdwcHPObjs);
  3895. PRINTF(szFormat, "SymbolObj ", gdwcSYObjs);
  3896. PRINTF(szFormat, "RSAccessObj ", gdwcRSObjs);
  3897. PRINTF(szFormat, "PassHookObj ", gdwcPHObjs);
  3898. PRINTF(szFormat, "DataObj ", gdwcODObjs);
  3899. PRINTF(szFormat, "NSObj ", gdwcNSObjs);
  3900. PRINTF(szFormat, "OwnerObj ", gdwcOOObjs);
  3901. PRINTF(szFormat, "BuffFieldObj ", gdwcBFObjs);
  3902. PRINTF(szFormat, "StrDataObj ", gdwcSDObjs);
  3903. PRINTF(szFormat, "BuffDataObj ", gdwcBDObjs);
  3904. PRINTF(szFormat, "PackageObj ", gdwcPKObjs);
  3905. PRINTF(szFormat, "FieldUnitObj ", gdwcFUObjs);
  3906. PRINTF(szFormat, "BankFieldObj ", gdwcKFObjs);
  3907. PRINTF(szFormat, "FieldObj ", gdwcFObjs);
  3908. PRINTF(szFormat, "IndexFieldObj", gdwcIFObjs);
  3909. PRINTF(szFormat, "OpRegion ", gdwcORObjs);
  3910. PRINTF(szFormat, "MutexObj ", gdwcMTObjs);
  3911. PRINTF(szFormat, "EventObj ", gdwcEVObjs);
  3912. PRINTF(szFormat, "MethodObj ", gdwcMEObjs);
  3913. PRINTF(szFormat, "PowerResObj ", gdwcPRObjs);
  3914. PRINTF(szFormat, "ProcessorObj ", gdwcPCObjs);
  3915. PRINTF(szFormat, "CtxtResObj ", gdwcCRObjs);
  3916. PRINTF(szFormat, "MiscObj ",
  3917. gdwcMemObjs - gdwcCTObjs - gdwcHPObjs - gdwcSYObjs - gdwcRSObjs -
  3918. gdwcPHObjs - gdwcCRObjs);
  3919. } //DumpMemObjCounts
  3920. #endif //ifdef DEBUG