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.

3439 lines
99 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. /*** Local function prototypes
  13. */
  14. LONG LOCAL AMLIDbgBC(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  15. ULONG dwNonSWArgs);
  16. LONG LOCAL AMLIDbgBD(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  17. ULONG dwNonSWArgs);
  18. LONG LOCAL AMLIDbgBE(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  19. ULONG dwNonSWArgs);
  20. LONG LOCAL AMLIDbgBL(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  21. ULONG dwNonSWArgs);
  22. LONG LOCAL AMLIDbgBP(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  23. ULONG dwNonSWArgs);
  24. LONG LOCAL AddBrkPt(ULONG_PTR uipBrkPtAddr);
  25. LONG LOCAL ClearBrkPt(int iBrkPt);
  26. LONG LOCAL SetBrkPtState(int iBrkPt, BOOLEAN fEnable);
  27. LONG LOCAL EnableDisableBP(PSZ pszArg, BOOLEAN fEnable, ULONG dwArgNum);
  28. LONG LOCAL AMLIDbgCL(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  29. ULONG dwNonSWArgs);
  30. LONG LOCAL AMLIDbgDebugger(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  31. ULONG dwNonSWArgs);
  32. #ifdef DEBUG
  33. LONG LOCAL AMLIDbgDH(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  34. ULONG dwNonSWArgs);
  35. LONG LOCAL DumpHeap(ULONG_PTR uipHeap, ULONG dwSize);
  36. #endif
  37. LONG LOCAL AMLIDbgDL(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  38. ULONG dwNonSWArgs);
  39. LONG LOCAL AMLIDbgDNS(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  40. ULONG dwNonSWArgs);
  41. LONG LOCAL DumpNSObj(PSZ pszPath, BOOLEAN fRecursive);
  42. VOID LOCAL DumpNSTree(PNSOBJ pnsObj, ULONG dwLevel);
  43. LONG LOCAL AMLIDbgDO(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  44. ULONG dwNonSWArgs);
  45. LONG LOCAL AMLIDbgDS(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  46. ULONG dwNonSWArgs);
  47. LONG LOCAL DumpStack(ULONG_PTR uipCtxt, PCTXT pctxt, BOOLEAN fVerbose);
  48. LONG LOCAL AMLIDbgFind(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  49. ULONG dwNonSWArgs);
  50. BOOLEAN LOCAL FindNSObj(NAMESEG dwName, PNSOBJ pnsRoot);
  51. LONG LOCAL AMLIDbgLC(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  52. ULONG dwNonSWArgs);
  53. LONG LOCAL AMLIDbgLN(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  54. ULONG dwNonSWArgs);
  55. LONG LOCAL AMLIDbgP(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  56. ULONG dwNonSWArgs);
  57. LONG LOCAL AMLIDbgR(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  58. ULONG dwNonSWArgs);
  59. LONG LOCAL DumpCtxt(ULONG_PTR uipCtxt);
  60. LONG LOCAL AMLIDbgSet(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  61. ULONG dwNonSWArgs);
  62. LONG LOCAL AMLIDbgT(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  63. ULONG dwNonSWArgs);
  64. LONG LOCAL AMLIDbgU(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  65. ULONG dwNonSWArgs);
  66. PSZ LOCAL GetObjectPath(PNSOBJ pns);
  67. PSZ LOCAL GetObjAddrPath(ULONG_PTR uipns);
  68. VOID LOCAL DumpObject(POBJDATA pdata, PSZ pszName, int iLevel);
  69. PSZ LOCAL GetObjectTypeName(ULONG dwObjType);
  70. PSZ LOCAL GetRegionSpaceName(UCHAR bRegionSpace);
  71. BOOLEAN LOCAL FindObjSymbol(ULONG_PTR uipObj, PULONG_PTR puipns,
  72. PULONG pdwOffset);
  73. VOID LOCAL PrintBuffData(PUCHAR pb, ULONG dwLen);
  74. VOID LOCAL PrintSymbol(ULONG_PTR uip);
  75. LONG LOCAL EvalExpr(PSZ pszArg, PULONG_PTR puipValue, BOOLEAN *pfPhysical,
  76. PULONG_PTR puipns, PULONG pdwOffset);
  77. BOOLEAN LOCAL IsNumber(PSZ pszStr, ULONG dwBase, PULONG_PTR puipValue);
  78. LONG LOCAL AMLITraceEnable(BOOL fEnable);
  79. /*** Local data
  80. */
  81. char gcszTokenSeps[] = " \t\n";
  82. ULONG dwfDebuggerON = 0, dwfDebuggerOFF = 0;
  83. ULONG dwfAMLIInitON = 0, dwfAMLIInitOFF = 0;
  84. ULONG dwCmdArg = 0;
  85. CMDARG ArgsHelp[] =
  86. {
  87. NULL, AT_ACTION, 0, NULL, 0, AMLIDbgHelp,
  88. NULL, AT_END, 0, NULL, 0, NULL
  89. };
  90. CMDARG ArgsBC[] =
  91. {
  92. NULL, AT_ACTION, 0, NULL, 0, AMLIDbgBC,
  93. NULL, AT_END, 0, NULL, 0, NULL
  94. };
  95. CMDARG ArgsBD[] =
  96. {
  97. NULL, AT_ACTION, 0, NULL, 0, AMLIDbgBD,
  98. NULL, AT_END, 0, NULL, 0, NULL
  99. };
  100. CMDARG ArgsBE[] =
  101. {
  102. NULL, AT_ACTION, 0, NULL, 0, AMLIDbgBE,
  103. NULL, AT_END, 0, NULL, 0, NULL
  104. };
  105. CMDARG ArgsBP[] =
  106. {
  107. NULL, AT_ACTION, 0, NULL, 0, AMLIDbgBP,
  108. NULL, AT_END, 0, NULL, 0, NULL
  109. };
  110. #ifdef DEBUG
  111. CMDARG ArgsDH[] =
  112. {
  113. NULL, AT_ACTION, 0, NULL, 0, AMLIDbgDH,
  114. NULL, AT_END, 0, NULL, 0, NULL
  115. };
  116. #endif
  117. CMDARG ArgsDNS[] =
  118. {
  119. "s", AT_ENABLE, 0, &dwCmdArg, DNSF_RECURSE, NULL,
  120. NULL, AT_ACTION, 0, NULL, 0, AMLIDbgDNS,
  121. NULL, AT_END, 0, NULL, 0, NULL
  122. };
  123. CMDARG ArgsDO[] =
  124. {
  125. NULL, AT_ACTION, 0, NULL, 0, AMLIDbgDO,
  126. NULL, AT_END, 0, NULL, 0, NULL
  127. };
  128. CMDARG ArgsDS[] =
  129. {
  130. #ifdef DEBUG
  131. "v", AT_ENABLE, 0, &dwCmdArg, DSF_VERBOSE, NULL,
  132. #endif
  133. NULL, AT_ACTION, 0, NULL, 0, AMLIDbgDS,
  134. NULL, AT_END, 0, NULL, 0, NULL
  135. };
  136. CMDARG ArgsFind[] =
  137. {
  138. NULL, AT_ACTION, 0, NULL, 0, AMLIDbgFind,
  139. NULL, AT_END, 0, NULL, 0, NULL
  140. };
  141. CMDARG ArgsLN[] =
  142. {
  143. NULL, AT_ACTION, 0, NULL, 0, AMLIDbgLN,
  144. NULL, AT_END, 0, NULL, 0, NULL
  145. };
  146. CMDARG ArgsR[] =
  147. {
  148. NULL, AT_ACTION, 0, NULL, 0, AMLIDbgR,
  149. NULL, AT_END, 0, NULL, 0, NULL
  150. };
  151. CMDARG ArgsSet[] =
  152. {
  153. "traceon", AT_ENABLE, 0, &dwfDebuggerON, DBGF_AMLTRACE_ON, NULL,
  154. "traceoff", AT_ENABLE, 0, &dwfDebuggerOFF, DBGF_AMLTRACE_ON, NULL,
  155. "spewon", AT_ENABLE, 0, &dwfDebuggerON, DBGF_DEBUG_SPEW_ON, NULL,
  156. "spewoff", AT_ENABLE, 0, &dwfDebuggerOFF, DBGF_DEBUG_SPEW_ON, NULL,
  157. "nesttraceon", AT_ENABLE, 0, &dwfDebuggerOFF, DBGF_TRACE_NONEST, NULL,
  158. "nesttraceoff", AT_ENABLE, 0, &dwfDebuggerON, DBGF_TRACE_NONEST, NULL,
  159. "lbrkon", AT_ENABLE, 0, &dwfAMLIInitON, AMLIIF_LOADDDB_BREAK, NULL,
  160. "lbrkoff", AT_ENABLE, 0, &dwfAMLIInitOFF, AMLIIF_LOADDDB_BREAK, NULL,
  161. "errbrkon", AT_ENABLE, 0, &dwfDebuggerON, DBGF_ERRBREAK_ON, NULL,
  162. "errbrkoff", AT_ENABLE, 0, &dwfDebuggerOFF, DBGF_ERRBREAK_ON, NULL,
  163. "verboseon", AT_ENABLE, 0, &dwfDebuggerON, DBGF_VERBOSE_ON, NULL,
  164. "verboseoff", AT_ENABLE, 0, &dwfDebuggerOFF, DBGF_VERBOSE_ON, NULL,
  165. "logon", AT_ENABLE, 0, &dwfDebuggerON, DBGF_LOGEVENT_ON, NULL,
  166. "logoff", AT_ENABLE, 0, &dwfDebuggerOFF, DBGF_LOGEVENT_ON, NULL,
  167. "logmuton", AT_ENABLE, 0, &dwfDebuggerON, DBGF_LOGEVENT_MUTEX, NULL,
  168. "logmutoff", AT_ENABLE, 0, &dwfDebuggerOFF, DBGF_LOGEVENT_MUTEX, NULL,
  169. NULL, AT_END, 0, NULL, 0, NULL
  170. };
  171. CMDARG ArgsU[] =
  172. {
  173. NULL, AT_ACTION, 0, NULL, 0, AMLIDbgU,
  174. NULL, AT_END, 0, NULL, 0, NULL
  175. };
  176. DBGCMD DbgCmds[] =
  177. {
  178. "?", 0, ArgsHelp, AMLIDbgHelp,
  179. "bc", 0, ArgsBC, AMLIDbgBC,
  180. "bd", 0, ArgsBD, AMLIDbgBD,
  181. "be", 0, ArgsBE, AMLIDbgBE,
  182. "bl", 0, NULL, AMLIDbgBL,
  183. "bp", 0, ArgsBP, AMLIDbgBP,
  184. "cl", 0, NULL, AMLIDbgCL,
  185. "debugger", 0, NULL, AMLIDbgDebugger,
  186. #ifdef DEBUG
  187. "dh", 0, ArgsDH, AMLIDbgDH,
  188. #endif
  189. "dl", 0, NULL, AMLIDbgDL,
  190. "dns", 0, ArgsDNS, AMLIDbgDNS,
  191. "do", 0, ArgsDO, AMLIDbgDO,
  192. "ds", 0, ArgsDS, AMLIDbgDS,
  193. "find", 0, ArgsFind, AMLIDbgFind,
  194. "lc", 0, NULL, AMLIDbgLC,
  195. "ln", 0, ArgsLN, AMLIDbgLN,
  196. "p", 0, NULL, AMLIDbgP,
  197. "r", 0, ArgsR, AMLIDbgR,
  198. "set", 0, ArgsSet, AMLIDbgSet,
  199. "t", 0, NULL, AMLIDbgT,
  200. "u", 0, ArgsU, AMLIDbgU,
  201. NULL, 0, NULL, NULL
  202. };
  203. /***EP AMLIDbgExecuteCmd - Parse and execute a debugger command
  204. *
  205. * ENTRY
  206. * pszCmd -> command string
  207. *
  208. * EXIT
  209. * None
  210. */
  211. VOID STDCALL AMLIDbgExecuteCmd(PSZ pszCmd)
  212. {
  213. PSZ psz;
  214. int i;
  215. ULONG dwNumArgs = 0, dwNonSWArgs = 0;
  216. if ((psz = STRTOK(pszCmd, gcszTokenSeps)) != NULL)
  217. {
  218. for (i = 0; DbgCmds[i].pszCmd != NULL; i++)
  219. {
  220. if (STRCMP(psz, DbgCmds[i].pszCmd) == 0)
  221. {
  222. if ((DbgCmds[i].pArgTable == NULL) ||
  223. (DbgParseArgs(DbgCmds[i].pArgTable,
  224. &dwNumArgs,
  225. &dwNonSWArgs,
  226. gcszTokenSeps) == ARGERR_NONE))
  227. {
  228. ASSERT(DbgCmds[i].pfnCmd != NULL);
  229. DbgCmds[i].pfnCmd(NULL, NULL, dwNumArgs, dwNonSWArgs);
  230. }
  231. break;
  232. }
  233. }
  234. }
  235. else
  236. {
  237. DBG_ERROR(("invalid command \"%s\"", pszCmd));
  238. }
  239. } //AMLIDbgExecuteCmd
  240. /***LP AMLIDbgHelp - help
  241. *
  242. * ENTRY
  243. * pArg -> argument type entry
  244. * pszArg -> argument string
  245. * dwArgNum - argument number
  246. * dwNonSWArgs - number of non-switch arguments
  247. *
  248. * EXIT-SUCCESS
  249. * returns DBGERR_NONE
  250. * EXIT-FAILURE
  251. * returns negative error code
  252. */
  253. LONG LOCAL AMLIDbgHelp(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  254. ULONG dwNonSWArgs)
  255. {
  256. LONG rc = DBGERR_NONE;
  257. DEREF(pArg);
  258. DEREF(dwNonSWArgs);
  259. //
  260. // User typed ? <cmd>
  261. //
  262. if (pszArg != NULL)
  263. {
  264. if (STRCMP(pszArg, "?") == 0)
  265. {
  266. PRINTF("\nHelp:\n");
  267. PRINTF("Usage: ? [<Cmd>]\n");
  268. PRINTF("<Cmd> - command to get help on\n");
  269. }
  270. else if (STRCMP(pszArg, "bc") == 0)
  271. {
  272. PRINTF("\nClear Breakpoints:\n");
  273. PRINTF("Usage: bc <bp list> | *\n");
  274. PRINTF("<bp list> - list of breakpoint numbers\n");
  275. PRINTF("* - all breakpoints\n");
  276. }
  277. else if (STRCMP(pszArg, "bd") == 0)
  278. {
  279. PRINTF("\nDisable Breakpoints:\n");
  280. PRINTF("Usage: bd <bp list> | *\n");
  281. PRINTF("<bp list> - list of breakpoint numbers\n");
  282. PRINTF("* - all breakpoints\n");
  283. }
  284. else if (STRCMP(pszArg, "be") == 0)
  285. {
  286. PRINTF("\nEnable Breakpoints:\n");
  287. PRINTF("Usage: be <bp list> | *\n");
  288. PRINTF("<bp list> - list of breakpoint numbers\n");
  289. PRINTF("* - all breakpoints\n");
  290. }
  291. else if (STRCMP(pszArg, "bl") == 0)
  292. {
  293. PRINTF("\nList All Breakpoints:\n");
  294. PRINTF("Usage: bl\n");
  295. }
  296. else if (STRCMP(pszArg, "bp") == 0)
  297. {
  298. PRINTF("\nSet BreakPoints:\n");
  299. PRINTF("Usage: bp <MethodName> | <CodeAddr> ...\n");
  300. PRINTF("<MethodName> - full path of method name to have breakpoint set at\n");
  301. PRINTF("<CodeAddr> - address of AML code to have breakpoint set at\n");
  302. }
  303. else if (STRCMP(pszArg, "cl") == 0)
  304. {
  305. PRINTF("\nClear Event Log:\n");
  306. PRINTF("Usage: cl\n");
  307. }
  308. else if (STRCMP(pszArg, "debugger") == 0)
  309. {
  310. PRINTF("\nRequest entering AMLI debugger:\n");
  311. PRINTF("Usage: debugger\n");
  312. }
  313. #ifdef DEBUG
  314. else if (STRCMP(pszArg, "dh") == 0)
  315. {
  316. PRINTF("\nDump Heap:\n");
  317. PRINTF("Usage: dh [<Addr>]\n");
  318. PRINTF("<Addr> - address of the heap block, global heap if missing\n");
  319. }
  320. #endif
  321. else if (STRCMP(pszArg, "dl") == 0)
  322. {
  323. PRINTF("\nDump Event Log:\n");
  324. PRINTF("Usage: dl\n");
  325. }
  326. else if (STRCMP(pszArg, "dns") == 0)
  327. {
  328. PRINTF("\nDump Name Space Object:\n");
  329. PRINTF("Usage: dns [[/s] [<NameStr> | <Addr>]]\n");
  330. PRINTF("s - recursively dump the name space subtree\n");
  331. PRINTF("<NameStr> - name space path (dump whole name space if absent)\n");
  332. PRINTF("<Addr> - specify address of the name space object\n");
  333. }
  334. else if (STRCMP(pszArg, "do") == 0)
  335. {
  336. PRINTF("\nDump Data Object:\n");
  337. PRINTF("Usage: do <Addr>\n");
  338. PRINTF("<Addr> - address of the data object\n");
  339. }
  340. else if (STRCMP(pszArg, "ds") == 0)
  341. {
  342. PRINTF("\nDump Stack:\n");
  343. #ifdef DEBUG
  344. PRINTF("Usage: ds [/v] [<Addr>]\n");
  345. PRINTF("v - enable versbos mode\n");
  346. #else
  347. PRINTF("Usage: ds [<Addr>]\n");
  348. #endif
  349. PRINTF("<Addr> - address of the context block, use current context if missing\n");
  350. }
  351. else if (STRCMP(pszArg, "find") == 0)
  352. {
  353. PRINTF("\nFind NameSpace Object:\n");
  354. PRINTF("Usage: find <NameSeg>\n");
  355. PRINTF("<NameSeg> - Name of the NameSpace object without path\n");
  356. }
  357. else if (STRCMP(pszArg, "lc") == 0)
  358. {
  359. PRINTF("\nList All Contexts:\n");
  360. PRINTF("Usage: lc\n");
  361. }
  362. else if (STRCMP(pszArg, "ln") == 0)
  363. {
  364. PRINTF("\nDisplay Nearest Method Name:\n");
  365. PRINTF("Usage: ln [<MethodName> | <CodeAddr>]\n");
  366. PRINTF("<MethodName> - full path of method name\n");
  367. PRINTF("<CodeAddr> - address of AML code\n");
  368. }
  369. else if (STRCMP(pszArg, "p") == 0)
  370. {
  371. PRINTF("\nStep over AML Code\n");
  372. PRINTF("Usage: p\n");
  373. }
  374. else if (STRCMP(pszArg, "r") == 0)
  375. {
  376. PRINTF("\nDisplay Context Information:\n");
  377. PRINTF("Usage: r\n");
  378. }
  379. else if (STRCMP(pszArg, "set") == 0)
  380. {
  381. PRINTF("\nSet Debugger Options:\n");
  382. PRINTF("Usage: set [traceon | traceoff] [nesttraceon | nesttraceoff] [spewon | spewoff]\n"
  383. " [lbrkon | lbrkoff] [errbrkon | errbrkoff] [verboseon | verboseoff] \n"
  384. " [logon | logoff] [logmuton | logmutoff]\n");
  385. PRINTF("traceon - turn on AML tracing\n");
  386. PRINTF("traceoff - turn off AML tracing\n");
  387. PRINTF("nesttraceon - turn on nest tracing (only valid with traceon)\n");
  388. PRINTF("nesttraceoff - turn off nest tracing (only valid with traceon)\n");
  389. PRINTF("spewon - turn on debug spew\n");
  390. PRINTF("spewoff - turn off debug spew\n");
  391. PRINTF("lbrkon - enable load DDB completion break\n");
  392. PRINTF("lbrkoff - disable load DDB completion break\n");
  393. PRINTF("errbrkon - enable break on error\n");
  394. PRINTF("errbrkoff - disable break on error\n");
  395. PRINTF("verboseon - enable verbose mode\n");
  396. PRINTF("verboseoff - disable verbose mode\n");
  397. PRINTF("logon - enable event logging\n");
  398. PRINTF("logoff - disable event logging\n");
  399. PRINTF("logmuton - enable mutex event logging\n");
  400. PRINTF("logmutoff - disable mutex event logging\n");
  401. }
  402. else if (STRCMP(pszArg, "t") == 0)
  403. {
  404. PRINTF("\nTrace Into AML Code:\n");
  405. PRINTF("Usage: t\n");
  406. }
  407. else if (STRCMP(pszArg, "u") == 0)
  408. {
  409. PRINTF("\nUnassemble AML code:\n");
  410. PRINTF("Usage: u [<MethodName> | <CodeAddr>]\n");
  411. PRINTF("<MethodName> - full path of method name\n");
  412. PRINTF("<CodeAddr> - address of AML code\n");
  413. }
  414. else
  415. {
  416. DBG_ERROR(("invalid help command - %s", pszArg));
  417. rc = DBGERR_INVALID_CMD;
  418. }
  419. }
  420. //
  421. // User typed just a "?" without any arguments
  422. //
  423. else if (dwArgNum == 0)
  424. {
  425. PRINTF("\n");
  426. PRINTF("Help - ? [<Cmd>]\n");
  427. PRINTF("Clear Breakpoints - bc <bp list> | *\n");
  428. PRINTF("Disable Breakpoints - bd <bp list> | *\n");
  429. PRINTF("Enable Breakpoints - be <bp list> | *\n");
  430. PRINTF("List Breakpoints - bl\n");
  431. PRINTF("Set Breakpoints - bp <MethodName> | <CodeAddr> ...\n");
  432. PRINTF("Clear Event Log - cl\n");
  433. PRINTF("Request entering debugger- debugger\n");
  434. #ifdef DEBUG
  435. PRINTF("Dump Heap - dh [<Addr>]\n");
  436. #endif
  437. PRINTF("Dump Event Log - dl\n");
  438. PRINTF("Dump Name Space Object - dns [[/s] [<NameStr> | <Addr>]]\n");
  439. PRINTF("Dump Data Object - do <Addr>\n");
  440. #ifdef DEBUG
  441. PRINTF("Dump Stack - ds [/v] [<Addr>]\n");
  442. #else
  443. PRINTF("Dump Stack - ds [<Addr>]\n");
  444. #endif
  445. PRINTF("Find NameSpace Object - find <NameSeg>\n");
  446. PRINTF("List All Contexts - lc\n");
  447. PRINTF("Display Nearest Method - ln [<MethodName> | <CodeAddr>]\n");
  448. PRINTF("Step Over AML Code - p\n");
  449. PRINTF("Display Context Info. - r\n");
  450. PRINTF("Set Debugger Options - set [traceon | traceoff] [nesttraceon | nesttraceoff] [spewon | spewoff]\n"
  451. " [lbrkon | lbrkoff] [errbrkon | errbrkoff] [verboseon | verboseoff] \n"
  452. " [logon | logoff] [logmuton | logmutoff]\n");
  453. PRINTF("Trace Into AML Code - t\n");
  454. PRINTF("Unassemble AML code - u [<MethodName> | <CodeAddr>]\n");
  455. }
  456. return rc;
  457. } //AMLIDbgHelp
  458. /***LP AMLIDbgBC - Clear BreakPoint
  459. *
  460. * ENTRY
  461. * pArg -> argument type entry
  462. * pszArg -> argument string
  463. * dwArgNum - argument number
  464. * dwNonSWArgs - number of non-switch arguments
  465. *
  466. * EXIT-SUCCESS
  467. * returns DBGERR_NONE
  468. * EXIT-FAILURE
  469. * returns negative error code
  470. */
  471. LONG LOCAL AMLIDbgBC(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  472. ULONG dwNonSWArgs)
  473. {
  474. LONG rc = DBGERR_NONE;
  475. DEREF(pArg);
  476. DEREF(dwNonSWArgs);
  477. if (pszArg != NULL)
  478. {
  479. ULONG dwBrkPt;
  480. if (STRCMP(pszArg, "*") == 0)
  481. {
  482. for (dwBrkPt = 0; dwBrkPt < MAX_BRK_PTS; ++dwBrkPt)
  483. {
  484. if ((rc = ClearBrkPt((int)dwBrkPt)) != DBGERR_NONE)
  485. {
  486. break;
  487. }
  488. }
  489. }
  490. else if (IsNumber(pszArg, 10, (PULONG_PTR)&dwBrkPt))
  491. {
  492. rc = ClearBrkPt((int)dwBrkPt);
  493. }
  494. else
  495. {
  496. DBG_ERROR(("invalid breakpoint number"));
  497. rc = DBGERR_INVALID_CMD;
  498. }
  499. }
  500. else if (dwArgNum == 0)
  501. {
  502. DBG_ERROR(("invalid breakpoint command"));
  503. rc = DBGERR_INVALID_CMD;
  504. }
  505. return rc;
  506. } //AMLIDbgBC
  507. /***LP AMLIDbgBD - Disable BreakPoint
  508. *
  509. * ENTRY
  510. * pArg -> argument type entry
  511. * pszArg -> argument string
  512. * dwArgNum - argument number
  513. * dwNonSWArgs - number of non-switch arguments
  514. *
  515. * EXIT-SUCCESS
  516. * returns DBGERR_NONE
  517. * EXIT-FAILURE
  518. * returns negative error code
  519. */
  520. LONG LOCAL AMLIDbgBD(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  521. ULONG dwNonSWArgs)
  522. {
  523. LONG rc;
  524. DEREF(pArg);
  525. DEREF(dwNonSWArgs);
  526. rc = EnableDisableBP(pszArg, FALSE, dwArgNum);
  527. return rc;
  528. } //AMLIDbgBD
  529. /***LP AMLIDbgBE - Enable BreakPoint
  530. *
  531. * ENTRY
  532. * pArg -> argument type entry
  533. * pszArg -> argument string
  534. * dwArgNum - argument number
  535. * dwNonSWArgs - number of non-switch arguments
  536. *
  537. * EXIT-SUCCESS
  538. * returns DBGERR_NONE
  539. * EXIT-FAILURE
  540. * returns negative error code
  541. */
  542. LONG LOCAL AMLIDbgBE(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  543. ULONG dwNonSWArgs)
  544. {
  545. LONG rc;
  546. DEREF(pArg);
  547. DEREF(dwNonSWArgs);
  548. rc = EnableDisableBP(pszArg, TRUE, dwArgNum);
  549. return rc;
  550. } //AMLIDbgBE
  551. /***LP AMLIDbgBL - List BreakPoints
  552. *
  553. * ENTRY
  554. * pArg -> argument type entry
  555. * pszArg -> argument string
  556. * dwArgNum - argument number
  557. * dwNonSWArgs - number of non-switch arguments
  558. *
  559. * EXIT-SUCCESS
  560. * returns DBGERR_NONE
  561. * EXIT-FAILURE
  562. * returns negative error code
  563. */
  564. LONG LOCAL AMLIDbgBL(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  565. ULONG dwNonSWArgs)
  566. {
  567. LONG rc = DBGERR_NONE;
  568. DEREF(pArg);
  569. DEREF(dwArgNum);
  570. DEREF(dwNonSWArgs);
  571. if (pszArg == NULL)
  572. {
  573. BRKPT BrkPts[MAX_BRK_PTS];
  574. if (ReadMemory(FIELDADDROF("gDebugger", DBGR, BrkPts),
  575. BrkPts,
  576. sizeof(BrkPts),
  577. NULL))
  578. {
  579. int i;
  580. PNSOBJ pns;
  581. ULONG dwOffset;
  582. for (i = 0; i < MAX_BRK_PTS; ++i)
  583. {
  584. if (BrkPts[i].pbBrkPt != NULL)
  585. {
  586. PRINTF("%2d: <%c> ",
  587. i,
  588. (BrkPts[i].dwfBrkPt & BPF_ENABLED)? 'e': 'd');
  589. PrintSymbol((ULONG_PTR)BrkPts[i].pbBrkPt);
  590. PRINTF("\n");
  591. }
  592. }
  593. }
  594. else
  595. {
  596. DBG_ERROR(("failed to read break point table"));
  597. rc = DBGERR_CMD_FAILED;
  598. }
  599. }
  600. else
  601. {
  602. DBG_ERROR(("invalid breakpoint command"));
  603. rc = DBGERR_INVALID_CMD;
  604. }
  605. return rc;
  606. } //AMLIDbgBL
  607. /***LP AMLIDbgBP - Set BreakPoint
  608. *
  609. * ENTRY
  610. * pArg -> argument type entry
  611. * pszArg -> argument string
  612. * dwArgNum - argument number
  613. * dwNonSWArgs - number of non-switch arguments
  614. *
  615. * EXIT-SUCCESS
  616. * returns DBGERR_NONE
  617. * EXIT-FAILURE
  618. * returns negative error code
  619. */
  620. LONG LOCAL AMLIDbgBP(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  621. ULONG dwNonSWArgs)
  622. {
  623. LONG rc = DBGERR_NONE;
  624. DEREF(pArg);
  625. DEREF(dwNonSWArgs);
  626. if (pszArg != NULL)
  627. {
  628. ULONG_PTR uipBP;
  629. if ((rc = EvalExpr(pszArg, &uipBP, NULL, NULL, NULL)) == DBGERR_NONE)
  630. {
  631. rc = AddBrkPt(uipBP);
  632. }
  633. }
  634. else if (dwArgNum == 0)
  635. {
  636. DBG_ERROR(("invalid breakpoint command"));
  637. rc = DBGERR_INVALID_CMD;
  638. }
  639. return rc;
  640. } //AMLIDbgBP
  641. /***LP AddBrkPt - Add breakpoint
  642. *
  643. * ENTRY
  644. * uipBrkPtAddr - breakpoint address
  645. *
  646. * EXIT-SUCCESS
  647. * returns DBGERR_NONE
  648. * EXIT-FAILURE
  649. * returns DBGERR_CMD_FAILED
  650. */
  651. LONG LOCAL AddBrkPt(ULONG_PTR uipBrkPtAddr)
  652. {
  653. LONG rc = DBGERR_NONE;
  654. ULONG_PTR uipBrkPts = FIELDADDROF("gDebugger", DBGR, BrkPts), uipBP = 0;
  655. int i, iBrkPt;
  656. //
  657. // Look for a vacant slot.
  658. //
  659. for (i = 0, iBrkPt = -1; i < MAX_BRK_PTS; ++i)
  660. {
  661. uipBP = READMEMULONGPTR(uipBrkPts +
  662. sizeof(BRKPT)*i +
  663. FIELD_OFFSET(BRKPT, pbBrkPt));
  664. if ((uipBrkPtAddr == uipBP) || (iBrkPt == -1) && (uipBP == 0))
  665. {
  666. iBrkPt = i;
  667. }
  668. }
  669. if (iBrkPt == -1)
  670. {
  671. DBG_ERROR(("no free breakpoint"));
  672. rc = DBGERR_CMD_FAILED;
  673. }
  674. else if (uipBP == 0)
  675. {
  676. BRKPT BrkPt;
  677. BrkPt.pbBrkPt = (PUCHAR)uipBrkPtAddr;
  678. BrkPt.dwfBrkPt = BPF_ENABLED;
  679. if (!WriteMemory(uipBrkPts + sizeof(BRKPT)*iBrkPt,
  680. &BrkPt,
  681. sizeof(BrkPt),
  682. NULL))
  683. {
  684. DBG_ERROR(("failed to write to break point %d", iBrkPt));
  685. rc = DBGERR_CMD_FAILED;
  686. }
  687. }
  688. return rc;
  689. } //AddBrkPt
  690. /***LP ClearBrkPt - Clear breakpoint
  691. *
  692. * ENTRY
  693. * iBrkPt - breakpoint number
  694. *
  695. * EXIT-SUCCESS
  696. * returns DBGERR_NONE
  697. * EXIT-FAILURE
  698. * returns DBGERR_CMD_FAILED
  699. */
  700. LONG LOCAL ClearBrkPt(int iBrkPt)
  701. {
  702. LONG rc;
  703. if (iBrkPt < MAX_BRK_PTS)
  704. {
  705. MZERO(FIELDADDROF("gDebugger", DBGR, BrkPts) + sizeof(BRKPT)*iBrkPt,
  706. sizeof(BRKPT));
  707. rc = DBGERR_NONE;
  708. }
  709. else
  710. {
  711. DBG_ERROR(("invalid breakpoint number"));
  712. rc = DBGERR_CMD_FAILED;
  713. }
  714. return rc;
  715. } //ClearBrkPt
  716. /***LP SetBrkPtState - Enable/Disable breakpoint
  717. *
  718. * ENTRY
  719. * iBrkPt - breakpoint number
  720. * fEnable - enable breakpoint
  721. *
  722. * EXIT-SUCCESS
  723. * returns DBGERR_NONE
  724. * EXIT-FAILURE
  725. * returns DBGERR_CMD_FAILED
  726. */
  727. LONG LOCAL SetBrkPtState(int iBrkPt, BOOLEAN fEnable)
  728. {
  729. LONG rc = DBGERR_CMD_FAILED;
  730. if (iBrkPt < MAX_BRK_PTS)
  731. {
  732. ULONG_PTR uipBP = FIELDADDROF("gDebugger", DBGR, BrkPts) +
  733. sizeof(BRKPT)*iBrkPt;
  734. BRKPT BrkPt;
  735. if (ReadMemory(uipBP, &BrkPt, sizeof(BrkPt), NULL))
  736. {
  737. if (BrkPt.pbBrkPt != NULL)
  738. {
  739. if (fEnable)
  740. {
  741. BrkPt.dwfBrkPt |= BPF_ENABLED;
  742. }
  743. else
  744. {
  745. BrkPt.dwfBrkPt &= ~BPF_ENABLED;
  746. }
  747. if (WriteMemory(uipBP, &BrkPt, sizeof(BrkPt), NULL))
  748. {
  749. rc = DBGERR_NONE;
  750. }
  751. else
  752. {
  753. DBG_ERROR(("failed to write break point %d",
  754. iBrkPt));
  755. }
  756. }
  757. else
  758. {
  759. rc = DBGERR_NONE;
  760. }
  761. }
  762. else
  763. {
  764. DBG_ERROR(("failed to read break point %d", iBrkPt));
  765. }
  766. }
  767. else
  768. {
  769. DBG_ERROR(("invalid breakpoint number"));
  770. }
  771. return rc;
  772. } //SetBrkPtState
  773. /***LP EnableDisableBP - Enable/Disable BreakPoints
  774. *
  775. * ENTRY
  776. * pszArg -> argument string
  777. * fEnable - TRUE if enable breakpoints
  778. * dwArgNum - argument number
  779. *
  780. * EXIT-SUCCESS
  781. * returns DBGERR_NONE
  782. * EXIT-FAILURE
  783. * returns negative error code
  784. */
  785. LONG LOCAL EnableDisableBP(PSZ pszArg, BOOLEAN fEnable, ULONG dwArgNum)
  786. {
  787. LONG rc = DBGERR_NONE;
  788. if (pszArg != NULL)
  789. {
  790. ULONG dwBrkPt;
  791. if (STRCMP(pszArg, "*") == 0)
  792. {
  793. for (dwBrkPt = 0; dwBrkPt < MAX_BRK_PTS; ++dwBrkPt)
  794. {
  795. if ((rc = SetBrkPtState((int)dwBrkPt, fEnable)) != DBGERR_NONE)
  796. break;
  797. }
  798. }
  799. else if (IsNumber(pszArg, 10, (PULONG_PTR)&dwBrkPt))
  800. {
  801. rc = SetBrkPtState((int)dwBrkPt, fEnable);
  802. }
  803. else
  804. {
  805. DBG_ERROR(("invalid breakpoint number"));
  806. rc = DBGERR_INVALID_CMD;
  807. }
  808. }
  809. else if (dwArgNum == 0)
  810. {
  811. DBG_ERROR(("invalid breakpoint command"));
  812. rc = DBGERR_INVALID_CMD;
  813. }
  814. return rc;
  815. } //EnableDisableBP
  816. /***LP AMLIDbgCL - Clear event log
  817. *
  818. * ENTRY
  819. * pArg -> argument type entry
  820. * pszArg -> argument string
  821. * dwArgNum - argument number
  822. * dwNonSWArgs - number of non-switch arguments
  823. *
  824. * EXIT-SUCCESS
  825. * returns DBGERR_NONE
  826. * EXIT-FAILURE
  827. * returns negative error code
  828. */
  829. LONG LOCAL AMLIDbgCL(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  830. ULONG dwNonSWArgs)
  831. {
  832. LONG rc;
  833. DEREF(pArg);
  834. DEREF(dwArgNum);
  835. DEREF(dwNonSWArgs);
  836. if (pszArg == NULL)
  837. {
  838. ULONG_PTR uipEventLog = READMEMULONGPTR(FIELDADDROF("gDebugger",
  839. DBGR,
  840. pEventLog));
  841. if (uipEventLog != 0)
  842. {
  843. ULONG dwLogSize = READMEMDWORD(FIELDADDROF("gDebugger",
  844. DBGR,
  845. dwLogSize));
  846. ULONG i;
  847. //
  848. // For some reason, zeroing the whole eventlog in one shot
  849. // causes WriteMemory to hang, so I'll do one record at a
  850. // time.
  851. //
  852. for (i = 0; i < dwLogSize; ++i)
  853. {
  854. MZERO(uipEventLog + i*sizeof(EVENTLOG), sizeof(EVENTLOG));
  855. }
  856. i = 0;
  857. WRITEMEMDWORD(FIELDADDROF("gDebugger", DBGR, dwLogIndex), i);
  858. rc = DBGERR_NONE;
  859. }
  860. else
  861. {
  862. DBG_ERROR(("no event log allocated"));
  863. rc = DBGERR_CMD_FAILED;
  864. }
  865. }
  866. else
  867. {
  868. DBG_ERROR(("invalid CL command"));
  869. rc = DBGERR_INVALID_CMD;
  870. }
  871. return rc;
  872. } //AMLIDbgCL
  873. /***LP AMLIDbgDebugger - Request entering debugger
  874. *
  875. * ENTRY
  876. * pArg -> argument type entry
  877. * pszArg -> argument string
  878. * dwArgNum - argument number
  879. * dwNonSWArgs - number of non-switch arguments
  880. *
  881. * EXIT-SUCCESS
  882. * returns DBGERR_NONE
  883. * EXIT-FAILURE
  884. * returns negative error code
  885. */
  886. LONG LOCAL AMLIDbgDebugger(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  887. ULONG dwNonSWArgs)
  888. {
  889. LONG rc = DBGERR_NONE;
  890. DEREF(pArg);
  891. DEREF(dwArgNum);
  892. DEREF(dwNonSWArgs);
  893. if (pszArg == NULL)
  894. {
  895. ULONG_PTR uip = FIELDADDROF("gDebugger", DBGR, dwfDebugger);
  896. if (uip != 0)
  897. {
  898. ULONG dwData = READMEMDWORD(uip);
  899. dwData |= DBGF_DEBUGGER_REQ;
  900. if (!WRITEMEMDWORD(uip, dwData))
  901. {
  902. DBG_ERROR(("failed to write debugger flag at %x", uip));
  903. rc = DBGERR_CMD_FAILED;
  904. }
  905. }
  906. else
  907. {
  908. DBG_ERROR(("failed to get debugger flag address"));
  909. rc = DBGERR_CMD_FAILED;
  910. }
  911. }
  912. else
  913. {
  914. DBG_ERROR(("invalid debugger command"));
  915. rc = DBGERR_INVALID_CMD;
  916. }
  917. return rc;
  918. } //AMLIDbgDebugger
  919. #ifdef DEBUG
  920. /***LP AMLIDbgDH - Dump heap
  921. *
  922. * ENTRY
  923. * pArg -> argument type entry
  924. * pszArg -> argument string
  925. * dwArgNum - argument number
  926. * dwNonSWArgs - number of non-switch arguments
  927. *
  928. * EXIT-SUCCESS
  929. * returns DBGERR_NONE
  930. * EXIT-FAILURE
  931. * returns negative error code
  932. */
  933. LONG LOCAL AMLIDbgDH(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  934. ULONG dwNonSWArgs)
  935. {
  936. LONG rc = DBGERR_NONE;
  937. static ULONG_PTR uipHeap = 0;
  938. DEREF(pArg);
  939. DEREF(dwNonSWArgs);
  940. if (pszArg != NULL)
  941. {
  942. if (uipHeap == 0)
  943. {
  944. if (!IsNumber(pszArg, 16, &uipHeap))
  945. {
  946. DBG_ERROR(("invalid heap block address - %s", pszArg));
  947. rc = DBGERR_INVALID_CMD;
  948. }
  949. }
  950. else
  951. {
  952. DBG_ERROR(("invalid dump heap command"));
  953. rc = DBGERR_INVALID_CMD;
  954. }
  955. }
  956. else
  957. {
  958. HEAP HeapHdr;
  959. if (dwArgNum == 0)
  960. {
  961. uipHeap = READSYMULONGPTR("gpheapGlobal");
  962. }
  963. if (ReadMemory(uipHeap, &HeapHdr, sizeof(HeapHdr), NULL))
  964. {
  965. if (HeapHdr.dwSig == SIG_HEAP)
  966. {
  967. for (uipHeap = (ULONG_PTR)HeapHdr.pheapHead;
  968. (rc == DBGERR_NONE) &&
  969. (uipHeap != 0) &&
  970. ReadMemory(uipHeap, &HeapHdr, sizeof(HeapHdr), NULL);
  971. uipHeap = (ULONG_PTR)HeapHdr.pheapNext)
  972. {
  973. rc = DumpHeap(uipHeap,
  974. (ULONG)((ULONG_PTR)HeapHdr.pbHeapEnd - uipHeap));
  975. }
  976. }
  977. else
  978. {
  979. DBG_ERROR(("invalid heap block at %x", uipHeap));
  980. rc = DBGERR_CMD_FAILED;
  981. }
  982. }
  983. else
  984. {
  985. DBG_ERROR(("failed to read heap header at %x", uipHeap));
  986. rc = DBGERR_CMD_FAILED;
  987. }
  988. uipHeap = 0;
  989. }
  990. return rc;
  991. } //AMLIDbgDH
  992. /***LP DumpHeap - Dump heap block
  993. *
  994. * ENTRY
  995. * uipHeap - Heap block address
  996. * dwSize - Heap block size
  997. *
  998. * EXIT-SUCCESS
  999. * returns DBGERR_NONE
  1000. * EXIT-FAILURE
  1001. * returns negative error code
  1002. */
  1003. LONG LOCAL DumpHeap(ULONG_PTR uipHeap, ULONG dwSize)
  1004. {
  1005. LONG rc = DBGERR_NONE;
  1006. PHEAP pheap;
  1007. if ((pheap = LocalAlloc(LPTR, dwSize)) != NULL)
  1008. {
  1009. if (ReadMemory(uipHeap, pheap, dwSize, NULL))
  1010. {
  1011. PHEAPOBJHDR phobj;
  1012. ULONG_PTR uipXlate = uipHeap - (ULONG_PTR)pheap;
  1013. PRINTF("HeapBlock=%08x, HeapEnd=%08x, HeapHead=%08x, HeapNext=%08x\n",
  1014. uipHeap, pheap->pbHeapEnd, pheap->pheapHead, pheap->pheapNext);
  1015. PRINTF("HeapTop=%08x, HeapFreeList=%08x, UsedHeapSize=%d bytes\n",
  1016. pheap->pbHeapTop, pheap->plistFreeHeap,
  1017. pheap->pbHeapTop - uipHeap - FIELD_OFFSET(HEAP, Heap));
  1018. for (phobj = &pheap->Heap;
  1019. (PUCHAR)phobj < pheap->pbHeapTop - uipXlate;
  1020. phobj = (PHEAPOBJHDR)((PUCHAR)phobj + phobj->dwLen))
  1021. {
  1022. PRINTF("%08x: %s, Len=%08d, Prev=%08x, Next=%08x\n",
  1023. (ULONG_PTR)phobj + uipXlate,
  1024. (phobj->dwSig == 0)? "free": NameSegString(phobj->dwSig),
  1025. phobj->dwLen,
  1026. (phobj->dwSig == 0)? phobj->list.plistPrev: 0,
  1027. (phobj->dwSig == 0)? phobj->list.plistNext: 0);
  1028. }
  1029. }
  1030. else
  1031. {
  1032. DBG_ERROR(("failed to read heap block at %x, size=%d",
  1033. uipHeap, dwSize));
  1034. rc = DBGERR_CMD_FAILED;
  1035. }
  1036. LocalFree(pheap);
  1037. }
  1038. else
  1039. {
  1040. DBG_ERROR(("failed to allocate heap block (size=%d)", dwSize));
  1041. rc = DBGERR_CMD_FAILED;
  1042. }
  1043. return rc;
  1044. } //DumpHeap
  1045. #endif
  1046. /***LP AMLIDbgDL - Dump event log
  1047. *
  1048. * ENTRY
  1049. * pArg -> argument type entry
  1050. * pszArg -> argument string
  1051. * dwArgNum - argument number
  1052. * dwNonSWArgs - number of non-switch arguments
  1053. *
  1054. * EXIT-SUCCESS
  1055. * returns DBGERR_NONE
  1056. * EXIT-FAILURE
  1057. * returns negative error code
  1058. */
  1059. LONG LOCAL AMLIDbgDL(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  1060. ULONG dwNonSWArgs)
  1061. {
  1062. LONG rc = DBGERR_NONE;
  1063. DEREF(pArg);
  1064. DEREF(dwArgNum);
  1065. DEREF(dwNonSWArgs);
  1066. if (pszArg != NULL)
  1067. {
  1068. DBG_ERROR(("invalid DL command"));
  1069. rc = DBGERR_INVALID_CMD;
  1070. }
  1071. else
  1072. {
  1073. ULONG_PTR uipEventLog = READMEMULONGPTR(FIELDADDROF("gDebugger",
  1074. DBGR,
  1075. pEventLog));
  1076. if (uipEventLog != 0)
  1077. {
  1078. ULONG dwLogSize, dwLogIndex, i;
  1079. PEVENTLOG pEventLog;
  1080. PEVENTLOG plog;
  1081. TIME_FIELDS eventTime;
  1082. LARGE_INTEGER eventTimeInt;
  1083. dwLogSize = READMEMDWORD(FIELDADDROF("gDebugger", DBGR, dwLogSize));
  1084. dwLogIndex = READMEMDWORD(FIELDADDROF("gDebugger", DBGR, dwLogIndex));
  1085. if ((pEventLog = LocalAlloc(LPTR, sizeof(EVENTLOG)*dwLogSize)) !=
  1086. NULL)
  1087. {
  1088. if (ReadMemory(uipEventLog,
  1089. pEventLog,
  1090. sizeof(EVENTLOG)*dwLogSize,
  1091. NULL))
  1092. {
  1093. for (i = dwLogIndex;;)
  1094. {
  1095. if (pEventLog[i].dwEvent != 0)
  1096. {
  1097. plog = &pEventLog[i];
  1098. eventTimeInt.QuadPart = plog->ullTime;
  1099. RtlTimeToTimeFields( &eventTimeInt, &eventTime );
  1100. PRINTF(
  1101. "%d:%02d:%02d.%03d [%8x] ",
  1102. eventTime.Hour,
  1103. eventTime.Minute,
  1104. eventTime.Second,
  1105. eventTime.Milliseconds,
  1106. plog->uipData1
  1107. );
  1108. switch (plog->dwEvent) {
  1109. case 'AMUT':
  1110. PRINTF("AcquireMutext ");
  1111. break;
  1112. case 'RMUT':
  1113. PRINTF("ReleaseMutext ");
  1114. break;
  1115. case 'INSQ':
  1116. PRINTF("InsertReadyQueue ");
  1117. break;
  1118. case 'NEST':
  1119. PRINTF("NestContext ");
  1120. break;
  1121. case 'EVAL':
  1122. PRINTF("EvaluateContext ");
  1123. break;
  1124. case 'QCTX':
  1125. PRINTF("QueueContext ");
  1126. break;
  1127. case 'REST':
  1128. PRINTF("RestartContext ");
  1129. break;
  1130. case 'KICK':
  1131. PRINTF("QueueWorkItem ");
  1132. break;
  1133. case 'PAUS':
  1134. PRINTF("PauseInterpreter ");
  1135. break;
  1136. case 'RSCB':
  1137. PRINTF("RestartCtxtCallback ");
  1138. break;
  1139. case 'DONE':
  1140. PRINTF("EvalMethodComplete ");
  1141. break;
  1142. case 'ASCB':
  1143. PRINTF("AsyncCallBack ");
  1144. break;
  1145. case 'NSYN':
  1146. PRINTF("NestedSyncEvalObject ");
  1147. break;
  1148. case 'SYNC':
  1149. PRINTF("SyncEvalObject ");
  1150. break;
  1151. case 'ASYN':
  1152. PRINTF("AsyncEvalObject ");
  1153. break;
  1154. case 'NASY':
  1155. PRINTF("NestedAsyncEvalObject ");
  1156. break;
  1157. case 'RUNC':
  1158. PRINTF("RunContext ");
  1159. break;
  1160. case 'PACB':
  1161. PRINTF("PauseAsyncCallback ");
  1162. break;
  1163. case 'RUN!':
  1164. PRINTF("FinishedContext ");
  1165. break;
  1166. case 'RSUM':
  1167. PRINTF("ResumeInterpreter ");
  1168. break;
  1169. case 'RSTQ':
  1170. PRINTF("ResumeQueueWorkItem ");
  1171. break;
  1172. default:
  1173. break;
  1174. }
  1175. switch (plog->dwEvent)
  1176. {
  1177. case 'AMUT':
  1178. case 'RMUT':
  1179. PRINTF("\n Mut=%08x Owner=%08x dwcOwned=%d rc=%x\n",
  1180. plog->uipData2, plog->uipData3,
  1181. plog->uipData4, plog->uipData5);
  1182. break;
  1183. case 'INSQ':
  1184. case 'NEST':
  1185. case 'EVAL':
  1186. case 'QCTX':
  1187. case 'REST':
  1188. PRINTF("Context=%08x\n %s\n QTh=%08x QCt=%08x QFg=%08x pbOp=",
  1189. plog->uipData5,
  1190. GetObjAddrPath(plog->uipData6),
  1191. plog->uipData2, plog->uipData3,
  1192. plog->uipData4
  1193. );
  1194. PrintSymbol(plog->uipData7);
  1195. PRINTF("\n");
  1196. break;
  1197. case 'KICK':
  1198. case 'PAUS':
  1199. PRINTF("\n QTh=%08x QCt=%08x QFg=%08x rc=%x\n",
  1200. plog->uipData2, plog->uipData3,
  1201. plog->uipData4, plog->uipData5);
  1202. break;
  1203. case 'RSCB':
  1204. PRINTF("Context=%08x\n QTh=%08x QCt=%08x QFg=%08x\n",
  1205. plog->uipData5, plog->uipData2,
  1206. plog->uipData3, plog->uipData4);
  1207. break;
  1208. case 'DONE':
  1209. case 'ASCB':
  1210. PRINTF("rc=%x pEvent=%x\n %s\n QTh=%08x QCt=%08x QFg=%08x\n",
  1211. plog->uipData6, plog->uipData7,
  1212. GetObjAddrPath(plog->uipData5),
  1213. plog->uipData2, plog->uipData3,
  1214. plog->uipData4
  1215. );
  1216. break;
  1217. case 'NSYN':
  1218. case 'SYNC':
  1219. case 'ASYN':
  1220. PRINTF("IRQL=%2x\n %s\n QTh=%08x QCt=%08x QFg=%08x\n",
  1221. plog->uipData5 & 0xff,
  1222. GetObjAddrPath(plog->uipData6),
  1223. plog->uipData2, plog->uipData3,
  1224. plog->uipData4
  1225. );
  1226. break;
  1227. case 'NASY':
  1228. PRINTF("Context=%x CallBack=%x\n %s\n QTh=%08x QCt=%08x QFg=%08x\n",
  1229. plog->uipData6, plog->uipData7,
  1230. GetObjAddrPath(plog->uipData5),
  1231. plog->uipData2, plog->uipData3,
  1232. plog->uipData4
  1233. );
  1234. break;
  1235. case 'RUNC':
  1236. PRINTF("Context=%x\n %s\n QTh=%08x QCt=%08x QFg=%08x\n",
  1237. plog->uipData5,
  1238. GetObjAddrPath(plog->uipData6),
  1239. plog->uipData2, plog->uipData3,
  1240. plog->uipData4
  1241. );
  1242. break;
  1243. case 'PACB':
  1244. case 'RUN!':
  1245. PRINTF("Context=%x rc=%x\n QTh=%08x QCt=%08x QFg=%08x\n",
  1246. plog->uipData5, plog->uipData6,
  1247. plog->uipData2, plog->uipData3,
  1248. plog->uipData4
  1249. );
  1250. break;
  1251. case 'RSUM':
  1252. case 'RSTQ':
  1253. PRINTF("\n QTh=%08x QCt=%08x QFg=%08x\n",
  1254. plog->uipData1, plog->uipData2, plog->uipData3,
  1255. plog->uipData4);
  1256. break;
  1257. default:
  1258. PRINTF("D1=%08x,D2=%08x,D3=%08x,D4=%08x,D5=%08x,D6=%08x,D7=%08x\n",
  1259. plog->uipData1, plog->uipData2,
  1260. plog->uipData3, plog->uipData4,
  1261. plog->uipData5, plog->uipData6,
  1262. plog->uipData7);
  1263. }
  1264. }
  1265. PRINTF("\n");
  1266. if (++i >= dwLogSize)
  1267. {
  1268. i = 0;
  1269. }
  1270. if (i == dwLogIndex)
  1271. {
  1272. break;
  1273. }
  1274. }
  1275. }
  1276. else
  1277. {
  1278. DBG_ERROR(("failed to read event log buffer at %x",
  1279. uipEventLog));
  1280. rc = DBGERR_CMD_FAILED;
  1281. }
  1282. LocalFree(pEventLog);
  1283. }
  1284. else
  1285. {
  1286. DBG_ERROR(("failed to allocate event log buffer (size=%d)",
  1287. dwLogSize));
  1288. rc = DBGERR_CMD_FAILED;
  1289. }
  1290. }
  1291. else
  1292. {
  1293. DBG_ERROR(("no event log allocated"));
  1294. rc = DBGERR_CMD_FAILED;
  1295. }
  1296. }
  1297. return rc;
  1298. } //AMLIDbgDL
  1299. /***LP AMLIDbgDNS - Dump Name Space
  1300. *
  1301. * ENTRY
  1302. * pArg -> argument type entry
  1303. * pszArg -> argument string
  1304. * dwArgNum - argument number
  1305. * dwNonSWArgs - number of non-switch arguments
  1306. *
  1307. * EXIT-SUCCESS
  1308. * returns DBGERR_NONE
  1309. * EXIT-FAILURE
  1310. * returns negative error code
  1311. */
  1312. LONG LOCAL AMLIDbgDNS(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  1313. ULONG dwNonSWArgs)
  1314. {
  1315. LONG rc = DBGERR_NONE;
  1316. DEREF(pArg);
  1317. DEREF(dwNonSWArgs);
  1318. //
  1319. // User specified name space path or name space node address
  1320. //
  1321. if (pszArg != NULL)
  1322. {
  1323. ULONG_PTR uipNSObj;
  1324. NSOBJ NSObj;
  1325. if (!IsNumber(pszArg, 16, &uipNSObj))
  1326. {
  1327. //
  1328. // The argument is not an address, could be a name space path.
  1329. //
  1330. STRUPR(pszArg);
  1331. rc = DumpNSObj(pszArg,
  1332. (BOOLEAN)((dwCmdArg & DNSF_RECURSE) != 0));
  1333. }
  1334. else if (!ReadMemory(uipNSObj, &NSObj, sizeof(NSOBJ), NULL))
  1335. {
  1336. DBG_ERROR(("failed to read NameSpace object at %x", uipNSObj));
  1337. rc = DBGERR_INVALID_CMD;
  1338. }
  1339. else
  1340. {
  1341. PRINTF("\nACPI Name Space: %s (%x)\n",
  1342. GetObjAddrPath(uipNSObj), uipNSObj);
  1343. if (dwCmdArg & DNSF_RECURSE)
  1344. {
  1345. DumpNSTree(&NSObj, 0);
  1346. }
  1347. else
  1348. {
  1349. DumpObject(&NSObj.ObjData, NameSegString(NSObj.dwNameSeg), 0);
  1350. }
  1351. }
  1352. }
  1353. else
  1354. {
  1355. if (dwArgNum == 0)
  1356. {
  1357. //
  1358. // User typed "dns" but did not specify any name space path
  1359. // or address.
  1360. //
  1361. rc = DumpNSObj(NAMESTR_ROOT, TRUE);
  1362. }
  1363. dwCmdArg = 0;
  1364. }
  1365. return rc;
  1366. } //AMLIDbgDNS
  1367. /***LP DumpNSObj - Dump name space object
  1368. *
  1369. * ENTRY
  1370. * pszPath -> name space path string
  1371. * fRecursive - TRUE if also dump the subtree recursively
  1372. *
  1373. * EXIT-SUCCESS
  1374. * returns DBGERR_NONE
  1375. * EXIT-FAILURE
  1376. * returns DBGERR_ code
  1377. */
  1378. LONG LOCAL DumpNSObj(PSZ pszPath, BOOLEAN fRecursive)
  1379. {
  1380. LONG rc = DBGERR_NONE;
  1381. ULONG_PTR uipns;
  1382. NSOBJ NSObj;
  1383. if ((rc = GetNSObj(pszPath, NULL, &uipns, &NSObj,
  1384. NSF_LOCAL_SCOPE | NSF_WARN_NOTFOUND)) == DBGERR_NONE)
  1385. {
  1386. PRINTF("\nACPI Name Space: %s (%x)\n", pszPath, uipns);
  1387. if (!fRecursive)
  1388. {
  1389. char szName[sizeof(NAMESEG) + 1] = {0};
  1390. STRCPYN(szName, (PSZ)&NSObj.dwNameSeg, sizeof(NAMESEG));
  1391. DumpObject(&NSObj.ObjData, szName, 0);
  1392. }
  1393. else
  1394. {
  1395. DumpNSTree(&NSObj, 0);
  1396. }
  1397. }
  1398. return rc;
  1399. } //DumpNSObj
  1400. /***LP DumpNSTree - Dump all the name space objects in the subtree
  1401. *
  1402. * ENTRY
  1403. * pnsObj -> name space subtree root
  1404. * dwLevel - indent level
  1405. *
  1406. * EXIT
  1407. * None
  1408. */
  1409. VOID LOCAL DumpNSTree(PNSOBJ pnsObj, ULONG dwLevel)
  1410. {
  1411. char szName[sizeof(NAMESEG) + 1] = {0};
  1412. ULONG_PTR uipns, uipnsNext;
  1413. NSOBJ NSObj;
  1414. //
  1415. // First, dump myself
  1416. //
  1417. STRCPYN(szName, (PSZ)&pnsObj->dwNameSeg, sizeof(NAMESEG));
  1418. DumpObject(&pnsObj->ObjData, szName, dwLevel);
  1419. //
  1420. // Then, recursively dump each of my children
  1421. //
  1422. for (uipns = (ULONG_PTR)pnsObj->pnsFirstChild;
  1423. (uipns != 0) &&
  1424. ReadMemory(uipns, &NSObj, sizeof(NSObj), NULL);
  1425. uipns = uipnsNext)
  1426. {
  1427. //
  1428. // If this is the last child, we have no more.
  1429. //
  1430. uipnsNext = (ULONG_PTR)(((PNSOBJ)NSObj.list.plistNext ==
  1431. pnsObj->pnsFirstChild)?
  1432. NULL: NSObj.list.plistNext);
  1433. //
  1434. // Dump a child
  1435. //
  1436. DumpNSTree(&NSObj, dwLevel + 1);
  1437. }
  1438. } //DumpNSTree
  1439. /***LP AMLIDbgDO - Dump data object
  1440. *
  1441. * ENTRY
  1442. * pArg -> argument type entry
  1443. * pszArg -> argument string
  1444. * dwArgNum - argument number
  1445. * dwNonSWArgs - number of non-switch arguments
  1446. *
  1447. * EXIT-SUCCESS
  1448. * returns DBGERR_NONE
  1449. * EXIT-FAILURE
  1450. * returns negative error code
  1451. */
  1452. LONG LOCAL AMLIDbgDO(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  1453. ULONG dwNonSWArgs)
  1454. {
  1455. LONG rc = DBGERR_NONE;
  1456. DEREF(pArg);
  1457. DEREF(dwArgNum);
  1458. DEREF(dwNonSWArgs);
  1459. //
  1460. // User specified object address
  1461. //
  1462. if (pszArg != NULL)
  1463. {
  1464. ULONG_PTR uipObj;
  1465. OBJDATA Obj;
  1466. if (IsNumber(pszArg, 16, &uipObj))
  1467. {
  1468. if (ReadMemory(uipObj, &Obj, sizeof(Obj), NULL))
  1469. {
  1470. DumpObject(&Obj, NULL, 0);
  1471. }
  1472. else
  1473. {
  1474. DBG_ERROR(("failed to read object at %x", uipObj));
  1475. rc = DBGERR_INVALID_CMD;
  1476. }
  1477. }
  1478. else
  1479. {
  1480. DBG_ERROR(("invalid object address %s", pszArg));
  1481. rc = DBGERR_INVALID_CMD;
  1482. }
  1483. }
  1484. return rc;
  1485. } //AMLIDbgDO
  1486. /***LP AMLIDbgDS - Dump stack
  1487. *
  1488. * ENTRY
  1489. * pArg -> argument type entry
  1490. * pszArg -> argument string
  1491. * dwArgNum - argument number
  1492. * dwNonSWArgs - number of non-switch arguments
  1493. *
  1494. * EXIT-SUCCESS
  1495. * returns DBGERR_NONE
  1496. * EXIT-FAILURE
  1497. * returns negative error code
  1498. */
  1499. LONG LOCAL AMLIDbgDS(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  1500. ULONG dwNonSWArgs)
  1501. {
  1502. LONG rc = DBGERR_NONE;
  1503. static ULONG_PTR uipCtxt = 0;
  1504. DEREF(pArg);
  1505. DEREF(dwNonSWArgs);
  1506. if (pszArg != NULL)
  1507. {
  1508. if (uipCtxt == 0)
  1509. {
  1510. if (!IsNumber(pszArg, 16, &uipCtxt))
  1511. {
  1512. DBG_ERROR(("invalid context block address %s", pszArg));
  1513. rc = DBGERR_INVALID_CMD;
  1514. }
  1515. }
  1516. else
  1517. {
  1518. DBG_ERROR(("invalid dump stack command"));
  1519. rc = DBGERR_INVALID_CMD;
  1520. }
  1521. }
  1522. else
  1523. {
  1524. ULONG dwCtxtBlkSize = READSYMDWORD("gdwCtxtBlkSize");
  1525. PCTXT pctxt;
  1526. if (dwArgNum == 0)
  1527. {
  1528. uipCtxt = READMEMULONGPTR(FIELDADDROF("gReadyQueue",
  1529. CTXTQ,
  1530. pctxtCurrent));
  1531. }
  1532. if (uipCtxt == 0)
  1533. {
  1534. DBG_ERROR(("no current context"));
  1535. rc = DBGERR_CMD_FAILED;
  1536. }
  1537. else if ((pctxt = LocalAlloc(LPTR, dwCtxtBlkSize)) == NULL)
  1538. {
  1539. DBG_ERROR(("failed to allocate context block (size=%d)",
  1540. dwCtxtBlkSize));
  1541. rc = DBGERR_CMD_FAILED;
  1542. }
  1543. else
  1544. {
  1545. if (!ReadMemory(uipCtxt, pctxt, dwCtxtBlkSize, NULL))
  1546. {
  1547. DBG_ERROR(("failed to read context block (pctxt=%x, size=%d)",
  1548. uipCtxt, dwCtxtBlkSize));
  1549. rc = DBGERR_CMD_FAILED;
  1550. }
  1551. else if (pctxt->dwSig == SIG_CTXT)
  1552. {
  1553. rc = DumpStack(uipCtxt,
  1554. pctxt,
  1555. (BOOLEAN)((dwCmdArg & DSF_VERBOSE) != 0));
  1556. }
  1557. else
  1558. {
  1559. DBG_ERROR(("invalid context block at %x", uipCtxt));
  1560. rc = DBGERR_CMD_FAILED;
  1561. }
  1562. LocalFree(pctxt);
  1563. }
  1564. dwCmdArg = 0;
  1565. pctxt = NULL;
  1566. }
  1567. return rc;
  1568. } //AMLIDbgDS
  1569. /***LP DumpStack - Dump stack of a context block
  1570. *
  1571. * ENTRY
  1572. * uipCtxt - context block address
  1573. * pctxt -> CTXT
  1574. * fVerbose - TRUE if verbose mode on
  1575. *
  1576. * EXIT-SUCCESS
  1577. * returns DBGERR_NONE
  1578. * EXIT-FAILURE
  1579. * returns negative error code
  1580. */
  1581. LONG LOCAL DumpStack(ULONG_PTR uipCtxt, PCTXT pctxt, BOOLEAN fVerbose)
  1582. {
  1583. LONG rc = DBGERR_NONE;
  1584. ULONG_PTR uipXlate = uipCtxt - (ULONG_PTR)pctxt;
  1585. PFRAMEHDR pfh;
  1586. PUCHAR pbOp = NULL;
  1587. ASSERT(pctxt->dwSig == SIG_CTXT);
  1588. if (fVerbose)
  1589. {
  1590. PRINTF("CtxtBlock=%x, StackTop=%x, StackEnd=%x\n\n",
  1591. uipCtxt, pctxt->LocalHeap.pbHeapEnd, pctxt->pbCtxtEnd);
  1592. }
  1593. for (pfh = (PFRAMEHDR)(pctxt->LocalHeap.pbHeapEnd - uipXlate);
  1594. (PUCHAR)pfh < (PUCHAR)(pctxt->pbCtxtEnd - uipXlate);
  1595. pfh = (PFRAMEHDR)((PUCHAR)pfh + pfh->dwLen))
  1596. {
  1597. if (fVerbose)
  1598. {
  1599. PRINTF("%08x: %s, Len=%08d, FrameFlags=%08x, ParseFunc=%08x\n",
  1600. (ULONG_PTR)pfh + uipXlate, NameSegString(pfh->dwSig),
  1601. pfh->dwLen, pfh->dwfFrame, pfh->pfnParse);
  1602. }
  1603. if (pfh->dwSig == SIG_CALL)
  1604. {
  1605. int i;
  1606. PCALL pcall = (PCALL)pfh;
  1607. //
  1608. // This is a call frame, dump it.
  1609. //
  1610. PRINTF("%08x: %s(",
  1611. pbOp, GetObjAddrPath((ULONG_PTR)pcall->pnsMethod));
  1612. if (pcall->icArgs > 0)
  1613. {
  1614. POBJDATA pArgs = LocalAlloc(LPTR,
  1615. sizeof(OBJDATA)*pcall->icArgs);
  1616. if (pArgs != NULL)
  1617. {
  1618. if (ReadMemory((ULONG_PTR)pcall->pdataArgs,
  1619. pArgs,
  1620. sizeof(OBJDATA)*pcall->icArgs,
  1621. NULL))
  1622. {
  1623. for (i = 0; i < pcall->icArgs; ++i)
  1624. {
  1625. DumpObject(&pArgs[i], NULL, -1);
  1626. if (i + 1 < pcall->icArgs)
  1627. {
  1628. PRINTF(",");
  1629. }
  1630. }
  1631. }
  1632. else
  1633. {
  1634. DBG_ERROR(("failed to read argument objects at %x",
  1635. pcall->pdataArgs));
  1636. rc = DBGERR_CMD_FAILED;
  1637. }
  1638. LocalFree(pArgs);
  1639. }
  1640. else
  1641. {
  1642. DBG_ERROR(("failed to allocate argument objects (size=%d)",
  1643. sizeof(OBJDATA)*pcall->icArgs));
  1644. rc = DBGERR_CMD_FAILED;
  1645. }
  1646. }
  1647. PRINTF(")\n");
  1648. if ((rc == DBGERR_NONE) && fVerbose)
  1649. {
  1650. for (i = 0; i < MAX_NUM_LOCALS; ++i)
  1651. {
  1652. PRINTF("Local%d: ", i);
  1653. DumpObject(&pcall->Locals[i], NULL, 0);
  1654. }
  1655. }
  1656. }
  1657. else if (pfh->dwSig == SIG_SCOPE)
  1658. {
  1659. pbOp = ((PSCOPE)pfh)->pbOpRet;
  1660. }
  1661. }
  1662. return rc;
  1663. } //DumpStack
  1664. /***LP AMLIDbgFind - Find NameSpace Object
  1665. *
  1666. * ENTRY
  1667. * pArg -> argument type entry
  1668. * pszArg -> argument string
  1669. * dwfDataSize - data size flags
  1670. *
  1671. * EXIT-SUCCESS
  1672. * returns DBGERR_NONE
  1673. * EXIT-FAILURE
  1674. * returns negative error code
  1675. */
  1676. LONG LOCAL AMLIDbgFind(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  1677. ULONG dwNonSWArgs)
  1678. {
  1679. LONG rc = DBGERR_NONE;
  1680. DEREF(pArg);
  1681. DEREF(dwNonSWArgs);
  1682. if (pszArg != NULL)
  1683. {
  1684. ULONG dwLen;
  1685. NSOBJ NSRoot;
  1686. dwLen = STRLEN(pszArg);
  1687. STRUPR(pszArg);
  1688. if (dwLen > sizeof(NAMESEG))
  1689. {
  1690. DBG_ERROR(("invalid NameSeg - %s", pszArg));
  1691. rc = DBGERR_INVALID_CMD;
  1692. }
  1693. else if (ReadMemory(READSYMULONGPTR("gpnsNameSpaceRoot"),
  1694. &NSRoot, sizeof(NSRoot), NULL))
  1695. {
  1696. NAMESEG dwName;
  1697. dwName = NAMESEG_BLANK;
  1698. MEMCPY(&dwName, pszArg, dwLen);
  1699. if (!FindNSObj(dwName, &NSRoot))
  1700. {
  1701. PRINTF("No such NameSpace object - %s\n", pszArg);
  1702. }
  1703. }
  1704. else
  1705. {
  1706. DBG_ERROR(("failed to read NameSpace root object"));
  1707. }
  1708. }
  1709. else if (dwArgNum == 0)
  1710. {
  1711. DBG_ERROR(("invalid Find command"));
  1712. rc = DBGERR_INVALID_CMD;
  1713. }
  1714. return rc;
  1715. } //AMLIDbgFind
  1716. /***LP FindNSObj - Find and print the full path of a name space object
  1717. *
  1718. * ENTRY
  1719. * dwName - NameSeg of the name space object
  1720. * pnsRoot - root of subtree to search for object
  1721. *
  1722. * EXIT-SUCCESS
  1723. * returns TRUE - found at least one match
  1724. * EXIT-FAILURE
  1725. * returns FALSE - found no match
  1726. */
  1727. BOOLEAN LOCAL FindNSObj(NAMESEG dwName, PNSOBJ pnsRoot)
  1728. {
  1729. BOOLEAN rc = FALSE;
  1730. if (pnsRoot != NULL)
  1731. {
  1732. if (dwName == pnsRoot->dwNameSeg)
  1733. {
  1734. PRINTF("%s\n", GetObjectPath(pnsRoot));
  1735. rc = TRUE;
  1736. }
  1737. if (pnsRoot->pnsFirstChild != NULL)
  1738. {
  1739. ULONG_PTR uip, uipNext;
  1740. NSOBJ NSChild;
  1741. for (uip = (ULONG_PTR)pnsRoot->pnsFirstChild;
  1742. (uip != 0) &&
  1743. ReadMemory(uip, &NSChild, sizeof(NSChild), NULL);
  1744. uip = uipNext)
  1745. {
  1746. uipNext = (ULONG_PTR)
  1747. (((PNSOBJ)NSChild.list.plistNext ==
  1748. pnsRoot->pnsFirstChild)?
  1749. NULL: NSChild.list.plistNext);
  1750. rc |= FindNSObj(dwName, &NSChild);
  1751. }
  1752. }
  1753. }
  1754. return rc;
  1755. } //FindNSObj
  1756. /***LP AMLIDbgLC - List all contexts
  1757. *
  1758. * ENTRY
  1759. * pArg -> argument type entry
  1760. * pszArg -> argument string
  1761. * dwArgNum - argument number
  1762. * dwNonSWArgs - number of non-switch arguments
  1763. *
  1764. * EXIT-SUCCESS
  1765. * returns DBGERR_NONE
  1766. * EXIT-FAILURE
  1767. * returns negative error code
  1768. */
  1769. LONG LOCAL AMLIDbgLC(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  1770. ULONG dwNonSWArgs)
  1771. {
  1772. LONG rc = DBGERR_NONE;
  1773. DEREF(pArg);
  1774. DEREF(dwArgNum);
  1775. DEREF(dwNonSWArgs);
  1776. if (pszArg == NULL)
  1777. {
  1778. ULONG_PTR uipHead = READSYMULONGPTR("gplistCtxtHead");
  1779. if (uipHead != 0)
  1780. {
  1781. ULONG_PTR uipCurrentCtxt = READMEMULONGPTR(
  1782. FIELDADDROF("gReadyQueue",
  1783. CTXTQ,
  1784. pctxtCurrent));
  1785. ULONG_PTR uipCurrentThread = READMEMULONGPTR(
  1786. FIELDADDROF("gReadyQueue",
  1787. CTXTQ,
  1788. pkthCurrent));
  1789. ULONG_PTR uip, uipNext;
  1790. CTXT ctxt;
  1791. for (uip = uipHead - FIELD_OFFSET(CTXT, listCtxt);
  1792. (uip != 0) && (rc == DBGERR_NONE);
  1793. uip = uipNext)
  1794. {
  1795. if (ReadMemory(uip, &ctxt, sizeof(ctxt), NULL))
  1796. {
  1797. ASSERT(ctxt.dwSig == SIG_CTXT);
  1798. uipNext = ((ULONG_PTR)ctxt.listCtxt.plistNext == uipHead)?
  1799. 0:
  1800. (ULONG_PTR)ctxt.listCtxt.plistNext -
  1801. FIELD_OFFSET(CTXT, listCtxt);
  1802. PRINTF("%cCtxt=%08x, ThID=%08x, Flgs=%c%c%c%c%c%c%c%c%c, pbOp=%08x, Obj=%s\n",
  1803. (uip == uipCurrentCtxt)? '*': ' ',
  1804. uip,
  1805. (uip == uipCurrentCtxt)? uipCurrentThread: 0,
  1806. (ctxt.dwfCtxt & CTXTF_ASYNC_EVAL)? 'A': '-',
  1807. (ctxt.dwfCtxt & CTXTF_NEST_EVAL)? 'N': '-',
  1808. (ctxt.dwfCtxt & CTXTF_IN_READYQ)? 'Q': '-',
  1809. (ctxt.dwfCtxt & CTXTF_NEED_CALLBACK)? 'C': '-',
  1810. (ctxt.dwfCtxt & CTXTF_RUNNING)? 'R': '-',
  1811. (ctxt.dwfCtxt & CTXTF_READY)? 'W': '-',
  1812. (ctxt.dwfCtxt & CTXTF_TIMEOUT)? 'T': '-',
  1813. (ctxt.dwfCtxt & CTXTF_TIMER_DISPATCH)? 'D': '-',
  1814. (ctxt.dwfCtxt & CTXTF_TIMER_PENDING)? 'P': '-',
  1815. ctxt.pbOp, GetObjAddrPath((ULONG_PTR)ctxt.pnsObj));
  1816. }
  1817. else
  1818. {
  1819. DBG_ERROR(("failed to read ctxt header at %x", uip));
  1820. rc = DBGERR_CMD_FAILED;
  1821. }
  1822. }
  1823. }
  1824. }
  1825. else
  1826. {
  1827. DBG_ERROR(("invalid LC command"));
  1828. rc = DBGERR_INVALID_CMD;
  1829. }
  1830. return rc;
  1831. } //AMLIDbgLC
  1832. /***LP AMLIDbgLN - Display nearest symbol
  1833. *
  1834. * ENTRY
  1835. * pArg -> argument type entry
  1836. * pszArg -> argument string
  1837. * dwArgNum - argument number
  1838. * dwNonSWArgs - number of non-switch arguments
  1839. *
  1840. * EXIT-SUCCESS
  1841. * returns DBGERR_NONE
  1842. * EXIT-FAILURE
  1843. * returns negative error code
  1844. */
  1845. LONG LOCAL AMLIDbgLN(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  1846. ULONG dwNonSWArgs)
  1847. {
  1848. LONG rc = DBGERR_NONE;
  1849. ULONG_PTR uip;
  1850. DEREF(pArg);
  1851. DEREF(dwNonSWArgs);
  1852. if (pszArg != NULL)
  1853. {
  1854. if ((rc = EvalExpr(pszArg, &uip, NULL, NULL, NULL)) == DBGERR_NONE)
  1855. {
  1856. PrintSymbol(uip);
  1857. }
  1858. }
  1859. else if (dwArgNum == 0)
  1860. {
  1861. uip = READMEMULONGPTR(FIELDADDROF("gReadyQueue", CTXTQ, pctxtCurrent));
  1862. if (uip != 0)
  1863. {
  1864. PrintSymbol(READMEMULONGPTR(uip + FIELD_OFFSET(CTXT, pbOp)));
  1865. }
  1866. else
  1867. {
  1868. DBG_ERROR(("no current context"));
  1869. rc = DBGERR_CMD_FAILED;
  1870. }
  1871. }
  1872. return rc;
  1873. } //AMLIDbgLN
  1874. /***LP AMLIDbgP - Trace and step over an AML instruction
  1875. *
  1876. * ENTRY
  1877. * pArg -> argument type entry
  1878. * pszArg -> argument string
  1879. * dwArgNum - argument number
  1880. * dwNonSWArgs - number of non-switch arguments
  1881. *
  1882. * EXIT-SUCCESS
  1883. * returns DBGERR_NONE
  1884. * EXIT-FAILURE
  1885. * returns negative error code
  1886. */
  1887. LONG LOCAL AMLIDbgP(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  1888. ULONG dwNonSWArgs)
  1889. {
  1890. LONG rc = DBGERR_NONE;
  1891. DEREF(pArg);
  1892. DEREF(dwArgNum);
  1893. DEREF(dwNonSWArgs);
  1894. if (pszArg == NULL)
  1895. {
  1896. ULONG_PTR uip = FIELDADDROF("gDebugger", DBGR, dwfDebugger);
  1897. ULONG dwData;
  1898. dwData = READMEMDWORD(uip);
  1899. dwData |= DBGF_STEP_OVER;
  1900. if (!WRITEMEMDWORD(uip, dwData))
  1901. {
  1902. DBG_ERROR(("failed to write debugger flag at %x", uip));
  1903. rc = DBGERR_CMD_FAILED;
  1904. }
  1905. }
  1906. else
  1907. {
  1908. DBG_ERROR(("invalid step command"));
  1909. rc = DBGERR_INVALID_CMD;
  1910. }
  1911. return rc;
  1912. } //DebugStep
  1913. /***LP AMLIDbgR - Dump debugger context
  1914. *
  1915. * ENTRY
  1916. * pArg -> argument type entry
  1917. * pszArg -> argument string
  1918. * dwArgNum - argument number
  1919. * dwNonSWArgs - number of non-switch arguments
  1920. *
  1921. * EXIT-SUCCESS
  1922. * returns DBGERR_NONE
  1923. * EXIT-FAILURE
  1924. * returns negative error code
  1925. */
  1926. LONG LOCAL AMLIDbgR(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  1927. ULONG dwNonSWArgs)
  1928. {
  1929. LONG rc = DBGERR_NONE;
  1930. ULONG_PTR uip;
  1931. DEREF(pArg);
  1932. DEREF(dwNonSWArgs);
  1933. if (pszArg != NULL)
  1934. {
  1935. if ((rc = EvalExpr(pszArg, &uip, NULL, NULL, NULL)) == DBGERR_NONE)
  1936. {
  1937. rc = DumpCtxt(uip);
  1938. }
  1939. }
  1940. else if (dwArgNum == 0)
  1941. {
  1942. rc = DumpCtxt(0);
  1943. }
  1944. return rc;
  1945. } //AMLIDbgR
  1946. /***LP DumpCtxt - Dump context
  1947. *
  1948. * ENTRY
  1949. * uipCtxt - Ctxt address
  1950. *
  1951. * EXIT
  1952. * None
  1953. */
  1954. LONG LOCAL DumpCtxt(ULONG_PTR uipCtxt)
  1955. {
  1956. LONG rc = DBGERR_NONE;
  1957. ULONG_PTR uipCurrentCtxt = READMEMULONGPTR(FIELDADDROF("gReadyQueue",
  1958. CTXTQ,
  1959. pctxtCurrent));
  1960. #ifdef DEBUG
  1961. ULONG_PTR uipCurrentThread = READMEMULONGPTR(FIELDADDROF("gReadyQueue",
  1962. CTXTQ,
  1963. pkthCurrent));
  1964. #endif
  1965. CTXT Ctxt;
  1966. if (uipCtxt == 0)
  1967. {
  1968. uipCtxt = uipCurrentCtxt;
  1969. }
  1970. if (uipCtxt == 0)
  1971. {
  1972. DBG_ERROR(("no current context"));
  1973. rc = DBGERR_CMD_FAILED;
  1974. }
  1975. else if (!ReadMemory(uipCtxt, &Ctxt, sizeof(Ctxt), NULL))
  1976. {
  1977. DBG_ERROR(("failed to read context header at %x", uipCtxt));
  1978. rc = DBGERR_CMD_FAILED;
  1979. }
  1980. else if (Ctxt.dwSig != SIG_CTXT)
  1981. {
  1982. DBG_ERROR(("invalid context block at %x", uipCtxt));
  1983. rc = DBGERR_CMD_FAILED;
  1984. }
  1985. else
  1986. {
  1987. #ifdef DEBUG
  1988. PRINTF("\nContext=%08x%c, Queue=%08x, ResList=%08x\n",
  1989. uipCtxt,
  1990. (uipCtxt == uipCurrentCtxt)? '*': ' ',
  1991. Ctxt.pplistCtxtQueue, Ctxt.plistResources);
  1992. PRINTF("ThreadID=%08x, Flags=%08x, pbOp=",
  1993. (uipCtxt == uipCurrentCtxt)? uipCurrentThread: 0,
  1994. Ctxt.dwfCtxt);
  1995. PrintSymbol((ULONG_PTR)Ctxt.pbOp);
  1996. PRINTF("\n");
  1997. PRINTF("StackTop=%08x, UsedStackSize=%d bytes, FreeStackSize=%d bytes\n",
  1998. Ctxt.LocalHeap.pbHeapEnd,
  1999. Ctxt.pbCtxtEnd - Ctxt.LocalHeap.pbHeapEnd,
  2000. Ctxt.LocalHeap.pbHeapEnd - Ctxt.LocalHeap.pbHeapTop);
  2001. PRINTF("LocalHeap=%08x, CurrentHeap=%08x, UsedHeapSize=%d bytes\n",
  2002. uipCtxt + FIELD_OFFSET(CTXT, LocalHeap),
  2003. Ctxt.pheapCurrent,
  2004. Ctxt.LocalHeap.pbHeapTop -
  2005. (uipCtxt + FIELD_OFFSET(CTXT, LocalHeap)));
  2006. PRINTF("Object=%s, Scope=%s, ObjectOwner=%x, SyncLevel=%x\n",
  2007. Ctxt.pnsObj? GetObjAddrPath((ULONG_PTR)Ctxt.pnsObj): "<none>",
  2008. Ctxt.pnsScope? GetObjAddrPath((ULONG_PTR)Ctxt.pnsScope): "<none>",
  2009. Ctxt.powner, Ctxt.dwSyncLevel);
  2010. PRINTF("AsyncCallBack=%x, CallBackData=%x, CallBackContext=%x\n",
  2011. Ctxt.pfnAsyncCallBack, Ctxt.pdataCallBack,
  2012. Ctxt.pvContext);
  2013. #endif
  2014. if (Ctxt.pcall != NULL)
  2015. {
  2016. CALL Call;
  2017. if (!ReadMemory((ULONG_PTR)Ctxt.pcall, &Call, sizeof(Call), NULL))
  2018. {
  2019. DBG_ERROR(("failed to read call frame at %x", Ctxt.pcall));
  2020. rc = DBGERR_CMD_FAILED;
  2021. }
  2022. else
  2023. {
  2024. int i;
  2025. PRINTF("\nMethodObject=%s\n",
  2026. Call.pnsMethod?
  2027. GetObjAddrPath((ULONG_PTR)Call.pnsMethod): "<none>");
  2028. if (Call.icArgs > 0)
  2029. {
  2030. POBJDATA pArgs = LocalAlloc(LPTR,
  2031. sizeof(OBJDATA)*
  2032. Call.icArgs);
  2033. if (pArgs == NULL)
  2034. {
  2035. DBG_ERROR(("failed to allocate arguemnt objects (size=%d)",
  2036. sizeof(OBJDATA)*Call.icArgs));
  2037. rc = DBGERR_CMD_FAILED;
  2038. }
  2039. else
  2040. {
  2041. if (ReadMemory((ULONG_PTR)Call.pdataArgs,
  2042. pArgs,
  2043. sizeof(OBJDATA)*Call.icArgs,
  2044. NULL))
  2045. {
  2046. for (i = 0; i < Call.icArgs; ++i)
  2047. {
  2048. PRINTF("%08x: Arg%d=",
  2049. Call.pdataArgs +
  2050. sizeof(OBJDATA)*i,
  2051. i);
  2052. DumpObject(&pArgs[i], NULL, 0);
  2053. }
  2054. }
  2055. else
  2056. {
  2057. DBG_ERROR(("failed to read arguemnt objects at %x",
  2058. Call.pdataArgs));
  2059. rc = DBGERR_CMD_FAILED;
  2060. }
  2061. LocalFree(pArgs);
  2062. }
  2063. }
  2064. for (i = 0; (rc == DBGERR_NONE) && (i < MAX_NUM_LOCALS); ++i)
  2065. {
  2066. PRINTF("%08x: Local%d=",
  2067. Ctxt.pcall + FIELD_OFFSET(CALL, Locals) +
  2068. sizeof(OBJDATA)*i,
  2069. i);
  2070. DumpObject(&Call.Locals[i], NULL, 0);
  2071. }
  2072. }
  2073. }
  2074. if (rc == DBGERR_NONE)
  2075. {
  2076. PRINTF("%08x: RetObj=", uipCtxt + FIELD_OFFSET(CTXT, Result));
  2077. DumpObject(&Ctxt.Result, NULL, 0);
  2078. }
  2079. if ((rc == DBGERR_NONE) && (Ctxt.plistResources != NULL))
  2080. {
  2081. ULONG_PTR uip, uipNext;
  2082. RESOURCE Res;
  2083. PRINTF("\nResources Owned:\n");
  2084. for (uip = (ULONG_PTR)Ctxt.plistResources -
  2085. FIELD_OFFSET(RESOURCE, list);
  2086. uip != 0; uip = uipNext)
  2087. {
  2088. if (ReadMemory(uip, &Res, sizeof(Res), NULL))
  2089. {
  2090. uipNext = (Res.list.plistNext != Ctxt.plistResources)?
  2091. (ULONG_PTR)Res.list.plistNext -
  2092. FIELD_OFFSET(RESOURCE, list): 0;
  2093. ASSERT(uipCtxt == (ULONG_PTR)Res.pctxtOwner);
  2094. PRINTF(" ResType=%s, ResObj=%x\n",
  2095. Res.dwResType == RESTYPE_MUTEX? "Mutex": "Unknown",
  2096. Res.pvResObj);
  2097. }
  2098. else
  2099. {
  2100. DBG_ERROR(("failed to read resource object at %x", uip));
  2101. rc = DBGERR_CMD_FAILED;
  2102. }
  2103. }
  2104. }
  2105. if (rc == DBGERR_NONE)
  2106. {
  2107. ULONG_PTR uipbOp = (ULONG_PTR)Ctxt.pbOp;
  2108. ULONG_PTR uipns = 0;
  2109. ULONG dwOffset = 0;
  2110. if (uipbOp == 0)
  2111. {
  2112. if (Ctxt.pnsObj != NULL)
  2113. {
  2114. uipns = (ULONG_PTR)Ctxt.pnsObj;
  2115. dwOffset = 0;
  2116. }
  2117. }
  2118. else if (!FindObjSymbol(uipbOp, &uipns, &dwOffset))
  2119. {
  2120. DBG_ERROR(("failed to find symbol at %x", Ctxt.pbOp));
  2121. rc = DBGERR_CMD_FAILED;
  2122. }
  2123. if ((rc == DBGERR_NONE) && (uipns != 0))
  2124. {
  2125. NSOBJ NSObj;
  2126. PMETHODOBJ pm;
  2127. if (!ReadMemory(uipns, &NSObj, sizeof(NSObj), NULL))
  2128. {
  2129. DBG_ERROR(("failed to read NameSpace object at %x", uipns));
  2130. rc = DBGERR_CMD_FAILED;
  2131. }
  2132. else if (NSObj.ObjData.dwDataType == OBJTYPE_METHOD)
  2133. {
  2134. if ((pm = GetObjBuff(&NSObj.ObjData)) == NULL)
  2135. {
  2136. DBG_ERROR(("failed to read method object at %x",
  2137. NSObj.ObjData.pbDataBuff));
  2138. rc = DBGERR_CMD_FAILED;
  2139. }
  2140. else
  2141. {
  2142. PUCHAR pbOp = &pm->abCodeBuff[dwOffset];
  2143. if (uipbOp == 0)
  2144. {
  2145. uipbOp = (ULONG_PTR)NSObj.ObjData.pbDataBuff +
  2146. FIELD_OFFSET(METHODOBJ, abCodeBuff);
  2147. }
  2148. PRINTF("\nNext AML Pointer: ");
  2149. PrintSymbol(uipbOp);
  2150. PRINTF("\n");
  2151. rc = UnAsmScope(&pbOp,
  2152. (PUCHAR)pm + NSObj.ObjData.dwDataLen,
  2153. uipbOp,
  2154. &NSObj,
  2155. 0,
  2156. 1);
  2157. PRINTF("\n");
  2158. LocalFree(pm);
  2159. }
  2160. }
  2161. }
  2162. }
  2163. }
  2164. return rc;
  2165. } //DumpCtxt
  2166. /***LP AMLIDbgSet - Set debugger options
  2167. *
  2168. * ENTRY
  2169. * pArg -> argument type entry
  2170. * pszArg -> argument string
  2171. * dwArgNum - argument number
  2172. * dwNonSWArgs - number of non-switch arguments
  2173. *
  2174. * EXIT-SUCCESS
  2175. * returns DBGERR_NONE
  2176. * EXIT-FAILURE
  2177. * returns negative error code
  2178. */
  2179. LONG LOCAL AMLIDbgSet(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  2180. ULONG dwNonSWArgs)
  2181. {
  2182. LONG rc = DBGERR_NONE;
  2183. ULONG_PTR uip1, uip2;
  2184. ULONG dwData1, dwData2;
  2185. DEREF(pArg);
  2186. DEREF(dwNonSWArgs);
  2187. uip1 = FIELDADDROF("gDebugger", DBGR, dwfDebugger);
  2188. uip2 = ADDROF("gdwfAMLIInit");
  2189. dwData1 = READMEMDWORD(uip1);
  2190. dwData2 = READMEMDWORD(uip2);
  2191. if ((pszArg == NULL) && (dwArgNum == 0))
  2192. {
  2193. PRINTF("AMLTrace =%s\n",
  2194. (dwData1 & DBGF_AMLTRACE_ON)? "on": "off");
  2195. PRINTF("AMLDebugSpew =%s\n",
  2196. (dwData1 & DBGF_DEBUG_SPEW_ON)? "on": "off");
  2197. PRINTF("LoadDDBBreak =%s\n",
  2198. (dwData2 & AMLIIF_LOADDDB_BREAK)? "on": "off");
  2199. PRINTF("ErrorBreak =%s\n",
  2200. (dwData1 & DBGF_ERRBREAK_ON)? "on": "off");
  2201. PRINTF("VerboseMode =%s\n",
  2202. (dwData1 & DBGF_VERBOSE_ON)? "on": "off");
  2203. PRINTF("LogEvent =%s\n",
  2204. (dwData1 & DBGF_LOGEVENT_ON)? "on": "off");
  2205. PRINTF("LogSize =%d\n",
  2206. READMEMDWORD(FIELDADDROF("gDebugger", DBGR, dwLogSize)));
  2207. }
  2208. else
  2209. {
  2210. dwData1 |= dwfDebuggerON;
  2211. dwData1 &= ~dwfDebuggerOFF;
  2212. dwData2 |= dwfAMLIInitON;
  2213. dwData2 &= ~dwfAMLIInitOFF;
  2214. if (!WRITEMEMDWORD(uip1, dwData1))
  2215. {
  2216. DBG_ERROR(("failed to write debugger flags at %x", uip1));
  2217. rc = DBGERR_CMD_FAILED;
  2218. }
  2219. else if (!WRITEMEMDWORD(uip2, dwData2))
  2220. {
  2221. DBG_ERROR(("failed to write init flags at %x", uip2));
  2222. rc = DBGERR_CMD_FAILED;
  2223. }
  2224. dwfDebuggerON = dwfDebuggerOFF = 0;
  2225. dwfAMLIInitON = dwfAMLIInitOFF = 0;
  2226. //
  2227. // Check to see if debug spew needs to be turned on. Turn on if needed.
  2228. //
  2229. if(dwData1 & DBGF_DEBUG_SPEW_ON)
  2230. {
  2231. rc = AMLITraceEnable(TRUE);
  2232. }
  2233. else
  2234. {
  2235. rc = AMLITraceEnable(FALSE);
  2236. }
  2237. }
  2238. return rc;
  2239. } //AMLIDbgSet
  2240. /***LP AMLIDbgT - Single-step an AML instruction
  2241. *
  2242. * ENTRY
  2243. * pArg -> argument type entry
  2244. * pszArg -> argument string
  2245. * dwArgNum - argument number
  2246. * dwNonSWArgs - number of non-switch arguments
  2247. *
  2248. * EXIT-SUCCESS
  2249. * returns DBGERR_NONE
  2250. * EXIT-FAILURE
  2251. * returns negative error code
  2252. */
  2253. LONG LOCAL AMLIDbgT(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  2254. ULONG dwNonSWArgs)
  2255. {
  2256. LONG rc = DBGERR_NONE;
  2257. DEREF(pArg);
  2258. DEREF(dwArgNum);
  2259. DEREF(dwNonSWArgs);
  2260. if (pszArg == NULL)
  2261. {
  2262. ULONG_PTR uip = FIELDADDROF("gDebugger", DBGR, dwfDebugger);
  2263. ULONG dwData;
  2264. dwData = READMEMDWORD(uip);
  2265. dwData |= DBGF_SINGLE_STEP;
  2266. if (!WRITEMEMDWORD(uip, dwData))
  2267. {
  2268. DBG_ERROR(("failed to write debugger flag at %x", uip));
  2269. rc = DBGERR_CMD_FAILED;
  2270. }
  2271. }
  2272. else
  2273. {
  2274. DBG_ERROR(("invalid trace command"));
  2275. rc = DBGERR_INVALID_CMD;
  2276. }
  2277. return rc;
  2278. } //AMLIDbgT
  2279. /***LP AMLIDbgU - Unassemble AML code
  2280. *
  2281. * ENTRY
  2282. * pArg -> argument type entry
  2283. * pszArg -> argument string
  2284. * dwArgNum - argument number
  2285. * dwNonSWArgs - number of non-switch arguments
  2286. *
  2287. * EXIT-SUCCESS
  2288. * returns DBGERR_NONE
  2289. * EXIT-FAILURE
  2290. * returns negative error code
  2291. */
  2292. LONG LOCAL AMLIDbgU(PCMDARG pArg, PSZ pszArg, ULONG dwArgNum,
  2293. ULONG dwNonSWArgs)
  2294. {
  2295. LONG rc = DBGERR_NONE;
  2296. static ULONG_PTR uipbOp = 0;
  2297. static PUCHAR pbBuff = NULL;
  2298. static ULONG dwBuffOffset = 0, dwBuffSize = 0;
  2299. static ULONG_PTR uipns = 0;
  2300. static NSOBJ NSObj = {0};
  2301. DEREF(pArg);
  2302. DEREF(dwArgNum);
  2303. DEREF(dwNonSWArgs);
  2304. //
  2305. // User specified name space path or memory address
  2306. //
  2307. if (pszArg != NULL)
  2308. {
  2309. uipbOp = 0;
  2310. if (pbBuff != NULL)
  2311. {
  2312. LocalFree(pbBuff);
  2313. pbBuff = NULL;
  2314. dwBuffSize = 0;
  2315. uipns = 0;
  2316. }
  2317. rc = EvalExpr(pszArg, &uipbOp, NULL, NULL, NULL);
  2318. }
  2319. else
  2320. {
  2321. if (uipbOp == 0)
  2322. {
  2323. ULONG_PTR uipCurrentCtxt = READMEMULONGPTR(
  2324. FIELDADDROF("gReadyQueue",
  2325. CTXTQ,
  2326. pctxtCurrent));
  2327. ASSERT(pbBuff == NULL);
  2328. if (uipCurrentCtxt != 0)
  2329. {
  2330. uipbOp = READMEMULONGPTR(uipCurrentCtxt +
  2331. FIELD_OFFSET(CTXT, pbOp));
  2332. if (uipbOp == 0)
  2333. {
  2334. uipns = READMEMULONGPTR(uipCurrentCtxt +
  2335. FIELD_OFFSET(CTXT, pnsObj));
  2336. if ((uipns != 0) &&
  2337. ReadMemory(uipns, &NSObj, sizeof(NSObj), NULL) &&
  2338. (NSObj.ObjData.dwDataType == OBJTYPE_METHOD))
  2339. {
  2340. uipbOp = (ULONG_PTR)NSObj.ObjData.pbDataBuff +
  2341. FIELD_OFFSET(METHODOBJ, abCodeBuff);
  2342. }
  2343. }
  2344. }
  2345. }
  2346. if (uipbOp == 0)
  2347. {
  2348. DBG_ERROR(("invalid AML code address %x", uipbOp));
  2349. rc = DBGERR_CMD_FAILED;
  2350. }
  2351. else
  2352. {
  2353. BOOLEAN fContinueLast = FALSE;
  2354. if (pbBuff == NULL)
  2355. {
  2356. ULONG dwOffset = 0;
  2357. if (uipns == 0)
  2358. {
  2359. if (FindObjSymbol(uipbOp, &uipns, &dwOffset))
  2360. {
  2361. if (!ReadMemory(uipns, &NSObj, sizeof(NSObj), NULL))
  2362. {
  2363. DBG_ERROR(("failed to read NameSpace object at %x",
  2364. uipns));
  2365. rc = DBGERR_CMD_FAILED;
  2366. }
  2367. }
  2368. }
  2369. if (rc == DBGERR_NONE)
  2370. {
  2371. if (uipns != 0)
  2372. {
  2373. dwBuffSize = NSObj.ObjData.dwDataLen -
  2374. FIELD_OFFSET(METHODOBJ, abCodeBuff) -
  2375. dwOffset;
  2376. }
  2377. else
  2378. {
  2379. //
  2380. // The uipbOp is not associated with any method object,
  2381. // so we must be unassembling some code in the middle
  2382. // of a DDB load. Set code length to 4K.
  2383. //
  2384. dwBuffSize = 4096;
  2385. }
  2386. dwBuffOffset = 0;
  2387. if ((pbBuff = LocalAlloc(LPTR, dwBuffSize)) == NULL)
  2388. {
  2389. DBG_ERROR(("failed to allocate code buffer (size=%d)",
  2390. dwBuffSize));
  2391. rc = DBGERR_CMD_FAILED;
  2392. }
  2393. else if (!ReadMemory(uipbOp, pbBuff, dwBuffSize, NULL))
  2394. {
  2395. DBG_ERROR(("failed to read AML code at %x (size=%d)",
  2396. uipbOp, dwBuffSize));
  2397. rc = DBGERR_CMD_FAILED;
  2398. }
  2399. }
  2400. }
  2401. else
  2402. {
  2403. fContinueLast = TRUE;
  2404. }
  2405. if (rc == DBGERR_NONE)
  2406. {
  2407. PUCHAR pbOp = pbBuff + dwBuffOffset;
  2408. rc = UnAsmScope(&pbOp,
  2409. pbBuff + dwBuffSize,
  2410. uipbOp + dwBuffOffset,
  2411. uipns? &NSObj: NULL,
  2412. fContinueLast? -1: 0,
  2413. 0);
  2414. PRINTF("\n");
  2415. dwBuffOffset = (ULONG)(pbOp - pbBuff);
  2416. }
  2417. }
  2418. }
  2419. return rc;
  2420. } //AMLIDbgU
  2421. /***LP GetObjectPath - get object namespace path
  2422. *
  2423. * ENTRY
  2424. * pns -> object
  2425. *
  2426. * EXIT
  2427. * returns name space path
  2428. */
  2429. PSZ LOCAL GetObjectPath(PNSOBJ pns)
  2430. {
  2431. static char szPath[MAX_NAME_LEN + 1] = {0};
  2432. NSOBJ NSParent;
  2433. int i;
  2434. if (pns != NULL)
  2435. {
  2436. if (pns->pnsParent == NULL)
  2437. {
  2438. STRCPY(szPath, "\\");
  2439. }
  2440. else if (ReadMemory((ULONG_PTR)pns->pnsParent,
  2441. &NSParent,
  2442. sizeof(NSParent),
  2443. NULL))
  2444. {
  2445. GetObjectPath(&NSParent);
  2446. if (NSParent.pnsParent != NULL)
  2447. {
  2448. STRCAT(szPath, ".");
  2449. }
  2450. STRCATN(szPath, (PSZ)&pns->dwNameSeg, sizeof(NAMESEG));
  2451. }
  2452. for (i = STRLEN(szPath) - 1; i >= 0; --i)
  2453. {
  2454. if (szPath[i] == '_')
  2455. szPath[i] = '\0';
  2456. else
  2457. break;
  2458. }
  2459. }
  2460. else
  2461. {
  2462. szPath[0] = '\0';
  2463. }
  2464. return szPath;
  2465. } //GetObjectPath
  2466. /***LP GetObjAddrPath - get object namespace path
  2467. *
  2468. * ENTRY
  2469. * uipns - object address
  2470. *
  2471. * EXIT
  2472. * returns name space path
  2473. */
  2474. PSZ LOCAL GetObjAddrPath(ULONG_PTR uipns)
  2475. {
  2476. PSZ psz = NULL;
  2477. NSOBJ NSObj;
  2478. if (uipns == 0)
  2479. {
  2480. psz = "<null>";
  2481. }
  2482. else if (ReadMemory(uipns, &NSObj, sizeof(NSObj), NULL))
  2483. {
  2484. psz = GetObjectPath(&NSObj);
  2485. }
  2486. else
  2487. {
  2488. DBG_ERROR(("failed to read NameSpace object at %x", uipns));
  2489. }
  2490. return psz;
  2491. } //GetObjAddrPath
  2492. /***LP DumpObject - Dump object info.
  2493. *
  2494. * ENTRY
  2495. * pdata -> data
  2496. * pszName -> object name
  2497. * iLevel - indent level
  2498. *
  2499. * EXIT
  2500. * None
  2501. *
  2502. * NOTE
  2503. * If iLevel is negative, no indentation and newline are printed.
  2504. */
  2505. VOID LOCAL DumpObject(POBJDATA pdata, PSZ pszName, int iLevel)
  2506. {
  2507. BOOLEAN fPrintNewLine = (BOOLEAN)(iLevel >= 0);
  2508. int i;
  2509. char szName1[sizeof(NAMESEG) + 1],
  2510. szName2[sizeof(NAMESEG) + 1];
  2511. for (i = 0; i < iLevel; ++i)
  2512. {
  2513. PRINTF("| ");
  2514. }
  2515. if (pszName == NULL)
  2516. {
  2517. pszName = "";
  2518. }
  2519. switch (pdata->dwDataType)
  2520. {
  2521. case OBJTYPE_UNKNOWN:
  2522. PRINTF("Unknown(%s)", pszName);
  2523. break;
  2524. case OBJTYPE_INTDATA:
  2525. PRINTF("Integer(%s:Value=0x%08x[%d])",
  2526. pszName, pdata->uipDataValue, pdata->uipDataValue);
  2527. break;
  2528. case OBJTYPE_STRDATA:
  2529. {
  2530. PSZ psz = (PSZ)GetObjBuff(pdata);
  2531. PRINTF("String(%s:Str=\"%s\")", pszName, psz);
  2532. LocalFree(psz);
  2533. break;
  2534. }
  2535. case OBJTYPE_BUFFDATA:
  2536. {
  2537. PUCHAR pbData = (PUCHAR)GetObjBuff(pdata);
  2538. PRINTF("Buffer(%s:Ptr=%x,Len=%d)",
  2539. pszName, pdata->pbDataBuff, pdata->dwDataLen);
  2540. PrintBuffData(pbData, pdata->dwDataLen);
  2541. LocalFree(pbData);
  2542. break;
  2543. }
  2544. case OBJTYPE_PKGDATA:
  2545. {
  2546. PPACKAGEOBJ ppkg = (PPACKAGEOBJ)GetObjBuff(pdata);
  2547. PRINTF("Package(%s:NumElements=%d){", pszName, ppkg->dwcElements);
  2548. if (fPrintNewLine)
  2549. {
  2550. PRINTF("\n");
  2551. }
  2552. for (i = 0; i < (int)ppkg->dwcElements; ++i)
  2553. {
  2554. DumpObject(&ppkg->adata[i],
  2555. NULL,
  2556. fPrintNewLine? iLevel + 1: -1);
  2557. if (!fPrintNewLine && (i < (int)ppkg->dwcElements))
  2558. {
  2559. PRINTF(",");
  2560. }
  2561. }
  2562. for (i = 0; i < iLevel; ++i)
  2563. {
  2564. PRINTF("| ");
  2565. }
  2566. PRINTF("}");
  2567. LocalFree(ppkg);
  2568. break;
  2569. }
  2570. case OBJTYPE_FIELDUNIT:
  2571. {
  2572. PFIELDUNITOBJ pfu = (PFIELDUNITOBJ)GetObjBuff(pdata);
  2573. PRINTF("FieldUnit(%s:FieldParent=%x,ByteOffset=0x%x,StartBit=0x%x,NumBits=%d,FieldFlags=0x%x)",
  2574. pszName,
  2575. pfu->pnsFieldParent,
  2576. pfu->FieldDesc.dwByteOffset,
  2577. pfu->FieldDesc.dwStartBitPos,
  2578. pfu->FieldDesc.dwNumBits,
  2579. pfu->FieldDesc.dwFieldFlags);
  2580. LocalFree(pfu);
  2581. break;
  2582. }
  2583. case OBJTYPE_DEVICE:
  2584. PRINTF("Device(%s)", pszName);
  2585. break;
  2586. case OBJTYPE_EVENT:
  2587. PRINTF("Event(%s:pKEvent=%x)", pszName, pdata->pbDataBuff);
  2588. break;
  2589. case OBJTYPE_METHOD:
  2590. {
  2591. PMETHODOBJ pm = (PMETHODOBJ)GetObjBuff(pdata);
  2592. PRINTF("Method(%s:Flags=0x%x,CodeBuff=%x,Len=%d)",
  2593. pszName, pm->bMethodFlags, pm->abCodeBuff,
  2594. pdata->dwDataLen - FIELD_OFFSET(METHODOBJ, abCodeBuff));
  2595. LocalFree(pm);
  2596. break;
  2597. }
  2598. case OBJTYPE_MUTEX:
  2599. PRINTF("Mutex(%s:pKMutex=%x)", pszName, pdata->pbDataBuff);
  2600. break;
  2601. case OBJTYPE_OPREGION:
  2602. {
  2603. POPREGIONOBJ pop = (POPREGIONOBJ)GetObjBuff(pdata);
  2604. PRINTF("OpRegion(%s:RegionSpace=%s,Offset=0x%x,Len=%d)",
  2605. pszName,
  2606. GetRegionSpaceName(pop->bRegionSpace),
  2607. pop->uipOffset,
  2608. pop->dwLen);
  2609. LocalFree(pop);
  2610. break;
  2611. }
  2612. case OBJTYPE_POWERRES:
  2613. {
  2614. PPOWERRESOBJ ppwres = (PPOWERRESOBJ)GetObjBuff(pdata);
  2615. PRINTF("PowerResource(%s:SystemLevel=0x%x,ResOrder=%d)",
  2616. pszName, ppwres->bSystemLevel, ppwres->bResOrder);
  2617. LocalFree(ppwres);
  2618. break;
  2619. }
  2620. case OBJTYPE_PROCESSOR:
  2621. {
  2622. PPROCESSOROBJ pproc = (PPROCESSOROBJ)GetObjBuff(pdata);
  2623. PRINTF("Processor(%s:ApicID=0x%x,PBlk=0x%x,PBlkLen=%d)",
  2624. pszName,
  2625. pproc->bApicID,
  2626. pproc->dwPBlk,
  2627. pproc->dwPBlkLen);
  2628. LocalFree(pproc);
  2629. break;
  2630. }
  2631. case OBJTYPE_THERMALZONE:
  2632. PRINTF("ThermalZone(%s)", pszName);
  2633. break;
  2634. case OBJTYPE_BUFFFIELD:
  2635. {
  2636. PBUFFFIELDOBJ pbf = (PBUFFFIELDOBJ)GetObjBuff(pdata);
  2637. PRINTF("BufferField(%s:Ptr=%x,Len=%d,ByteOffset=0x%x,StartBit=0x%x,NumBits=%d,FieldFlags=0x%x)",
  2638. pszName, pbf->pbDataBuff, pbf->dwBuffLen,
  2639. pbf->FieldDesc.dwByteOffset, pbf->FieldDesc.dwStartBitPos,
  2640. pbf->FieldDesc.dwNumBits, pbf->FieldDesc.dwFieldFlags);
  2641. LocalFree(pbf);
  2642. break;
  2643. }
  2644. case OBJTYPE_DDBHANDLE:
  2645. PRINTF("DDBHandle(%s:Handle=%x)", pszName, pdata->pbDataBuff);
  2646. break;
  2647. case OBJTYPE_OBJALIAS:
  2648. {
  2649. NSOBJ NSObj;
  2650. ULONG dwDataType;
  2651. if (ReadMemory((ULONG_PTR)pdata->pnsAlias,
  2652. &NSObj,
  2653. sizeof(NSObj),
  2654. NULL))
  2655. {
  2656. dwDataType = NSObj.ObjData.dwDataType;
  2657. }
  2658. else
  2659. {
  2660. dwDataType = OBJTYPE_UNKNOWN;
  2661. }
  2662. PRINTF("ObjectAlias(%s:Alias=%s,Type=%s)",
  2663. pszName, GetObjAddrPath((ULONG_PTR)pdata->pnsAlias),
  2664. GetObjectTypeName(dwDataType));
  2665. break;
  2666. }
  2667. case OBJTYPE_DATAALIAS:
  2668. {
  2669. OBJDATA Obj;
  2670. PRINTF("DataAlias(%s:Link=%x)", pszName, pdata->pdataAlias);
  2671. if (fPrintNewLine &&
  2672. ReadMemory((ULONG_PTR)pdata->pdataAlias,
  2673. &Obj,
  2674. sizeof(Obj),
  2675. NULL))
  2676. {
  2677. DumpObject(&Obj, NULL, iLevel + 1);
  2678. fPrintNewLine = FALSE;
  2679. }
  2680. break;
  2681. }
  2682. case OBJTYPE_BANKFIELD:
  2683. {
  2684. PBANKFIELDOBJ pbf = (PBANKFIELDOBJ)GetObjBuff(pdata);
  2685. NSOBJ NSObj;
  2686. if (ReadMemory((ULONG_PTR)pbf->pnsBase,
  2687. &NSObj,
  2688. sizeof(NSObj),
  2689. NULL))
  2690. {
  2691. STRCPYN(szName1, (PSZ)&NSObj.dwNameSeg, sizeof(NAMESEG));
  2692. }
  2693. else
  2694. {
  2695. szName1[0] = '\0';
  2696. }
  2697. if (ReadMemory((ULONG_PTR)pbf->pnsBank,
  2698. &NSObj,
  2699. sizeof(NSObj),
  2700. NULL))
  2701. {
  2702. STRCPYN(szName2, (PSZ)&NSObj.dwNameSeg, sizeof(NAMESEG));
  2703. }
  2704. else
  2705. {
  2706. szName2[0] = '\0';
  2707. }
  2708. PRINTF("BankField(%s:Base=%s,BankName=%s,BankValue=0x%x)",
  2709. pszName, szName1, szName2, pbf->dwBankValue);
  2710. LocalFree(pbf);
  2711. break;
  2712. }
  2713. case OBJTYPE_FIELD:
  2714. {
  2715. PFIELDOBJ pf = (PFIELDOBJ)GetObjBuff(pdata);
  2716. NSOBJ NSObj;
  2717. if (ReadMemory((ULONG_PTR)pf->pnsBase,
  2718. &NSObj,
  2719. sizeof(NSObj),
  2720. NULL))
  2721. {
  2722. STRCPYN(szName1, (PSZ)&NSObj.dwNameSeg, sizeof(NAMESEG));
  2723. }
  2724. else
  2725. {
  2726. szName1[0] = '\0';
  2727. }
  2728. PRINTF("Field(%s:Base=%s)", pszName, szName1);
  2729. LocalFree(pf);
  2730. break;
  2731. }
  2732. case OBJTYPE_INDEXFIELD:
  2733. {
  2734. PINDEXFIELDOBJ pif = (PINDEXFIELDOBJ)GetObjBuff(pdata);
  2735. NSOBJ NSObj;
  2736. if (ReadMemory((ULONG_PTR)pif->pnsIndex,
  2737. &NSObj,
  2738. sizeof(NSObj),
  2739. NULL))
  2740. {
  2741. STRCPYN(szName1, (PSZ)&NSObj.dwNameSeg, sizeof(NAMESEG));
  2742. }
  2743. else
  2744. {
  2745. szName1[0] = '\0';
  2746. }
  2747. if (ReadMemory((ULONG_PTR)pif->pnsData,
  2748. &NSObj,
  2749. sizeof(NSObj),
  2750. NULL))
  2751. {
  2752. STRCPYN(szName2, (PSZ)&NSObj.dwNameSeg, sizeof(NAMESEG));
  2753. }
  2754. else
  2755. {
  2756. szName2[0] = '\0';
  2757. }
  2758. PRINTF("IndexField(%s:IndexName=%s,DataName=%s)",
  2759. pszName, szName1, szName2);
  2760. LocalFree(pif);
  2761. break;
  2762. }
  2763. default:
  2764. DBG_ERROR(("unexpected data object type (type=%x)",
  2765. pdata->dwDataType));
  2766. }
  2767. if (fPrintNewLine)
  2768. {
  2769. PRINTF("\n");
  2770. }
  2771. } //DumpObject
  2772. /***LP GetObjectTypeName - get object type name
  2773. *
  2774. * ENTRY
  2775. * dwObjType - object type
  2776. *
  2777. * EXIT
  2778. * return object type name
  2779. */
  2780. PSZ LOCAL GetObjectTypeName(ULONG dwObjType)
  2781. {
  2782. PSZ psz = NULL;
  2783. int i;
  2784. static struct
  2785. {
  2786. ULONG dwObjType;
  2787. PSZ pszObjTypeName;
  2788. } ObjTypeTable[] =
  2789. {
  2790. OBJTYPE_UNKNOWN, "Unknown",
  2791. OBJTYPE_INTDATA, "Integer",
  2792. OBJTYPE_STRDATA, "String",
  2793. OBJTYPE_BUFFDATA, "Buffer",
  2794. OBJTYPE_PKGDATA, "Package",
  2795. OBJTYPE_FIELDUNIT, "FieldUnit",
  2796. OBJTYPE_DEVICE, "Device",
  2797. OBJTYPE_EVENT, "Event",
  2798. OBJTYPE_METHOD, "Method",
  2799. OBJTYPE_MUTEX, "Mutex",
  2800. OBJTYPE_OPREGION, "OpRegion",
  2801. OBJTYPE_POWERRES, "PowerResource",
  2802. OBJTYPE_PROCESSOR, "Processor",
  2803. OBJTYPE_THERMALZONE,"ThermalZone",
  2804. OBJTYPE_BUFFFIELD, "BuffField",
  2805. OBJTYPE_DDBHANDLE, "DDBHandle",
  2806. OBJTYPE_DEBUG, "Debug",
  2807. OBJTYPE_OBJALIAS, "ObjAlias",
  2808. OBJTYPE_DATAALIAS, "DataAlias",
  2809. OBJTYPE_BANKFIELD, "BankField",
  2810. OBJTYPE_FIELD, "Field",
  2811. OBJTYPE_INDEXFIELD, "IndexField",
  2812. OBJTYPE_DATA, "Data",
  2813. OBJTYPE_DATAFIELD, "DataField",
  2814. OBJTYPE_DATAOBJ, "DataObject",
  2815. 0, NULL
  2816. };
  2817. for (i = 0; ObjTypeTable[i].pszObjTypeName != NULL; ++i)
  2818. {
  2819. if (dwObjType == ObjTypeTable[i].dwObjType)
  2820. {
  2821. psz = ObjTypeTable[i].pszObjTypeName;
  2822. break;
  2823. }
  2824. }
  2825. return psz;
  2826. } //GetObjectTypeName
  2827. /***LP GetRegionSpaceName - get region space name
  2828. *
  2829. * ENTRY
  2830. * bRegionSpace - region space
  2831. *
  2832. * EXIT
  2833. * return object type name
  2834. */
  2835. PSZ LOCAL GetRegionSpaceName(UCHAR bRegionSpace)
  2836. {
  2837. PSZ psz = NULL;
  2838. int i;
  2839. static PSZ pszVendorDefined = "VendorDefined";
  2840. static struct
  2841. {
  2842. UCHAR bRegionSpace;
  2843. PSZ pszRegionSpaceName;
  2844. } RegionNameTable[] =
  2845. {
  2846. REGSPACE_MEM, "SystemMemory",
  2847. REGSPACE_IO, "SystemIO",
  2848. REGSPACE_PCICFG, "PCIConfigSpace",
  2849. REGSPACE_EC, "EmbeddedController",
  2850. REGSPACE_SMB, "SMBus",
  2851. 0, NULL
  2852. };
  2853. for (i = 0; RegionNameTable[i].pszRegionSpaceName != NULL; ++i)
  2854. {
  2855. if (bRegionSpace == RegionNameTable[i].bRegionSpace)
  2856. {
  2857. psz = RegionNameTable[i].pszRegionSpaceName;
  2858. break;
  2859. }
  2860. }
  2861. if (psz == NULL)
  2862. {
  2863. psz = pszVendorDefined;
  2864. }
  2865. return psz;
  2866. } //GetRegionSpaceName
  2867. /***LP FindObjSymbol - Find nearest object with given address
  2868. *
  2869. * ENTRY
  2870. * uipObj - address
  2871. * puipns -> to hold the nearest object address
  2872. * pdwOffset - to hold offset from the nearest object
  2873. *
  2874. * EXIT-SUCCESS
  2875. * returns TRUE - found a nearest object
  2876. * EXIT-FAILURE
  2877. * returns FALSE - cannot found nearest object
  2878. */
  2879. BOOLEAN LOCAL FindObjSymbol(ULONG_PTR uipObj, PULONG_PTR puipns,
  2880. PULONG pdwOffset)
  2881. {
  2882. BOOLEAN rc = FALSE;
  2883. ULONG_PTR uip;
  2884. OBJSYM ObjSym;
  2885. NSOBJ NSObj;
  2886. for (uip = READMEMULONGPTR(FIELDADDROF("gDebugger", DBGR, posSymbolList));
  2887. (uip != 0) &&
  2888. ReadMemory(uip, &ObjSym, sizeof(ObjSym), NULL);
  2889. uip = (ULONG_PTR)ObjSym.posNext)
  2890. {
  2891. if (uipObj <= (ULONG_PTR)ObjSym.pbOp)
  2892. {
  2893. if ((uipObj < (ULONG_PTR)ObjSym.pbOp) && (ObjSym.posPrev != NULL))
  2894. {
  2895. uip = (ULONG_PTR)ObjSym.posPrev;
  2896. ReadMemory(uip, &ObjSym, sizeof(ObjSym), NULL);
  2897. }
  2898. if ((uipObj >= (ULONG_PTR)ObjSym.pbOp) &&
  2899. ReadMemory((ULONG_PTR)ObjSym.pnsObj, &NSObj, sizeof(NSObj),
  2900. NULL) &&
  2901. (uipObj < (ULONG_PTR)NSObj.ObjData.pbDataBuff +
  2902. NSObj.ObjData.dwDataLen))
  2903. {
  2904. *puipns = (ULONG_PTR)ObjSym.pnsObj;
  2905. *pdwOffset = (ULONG)(uipObj - (ULONG_PTR)ObjSym.pbOp);
  2906. rc = TRUE;
  2907. }
  2908. break;
  2909. }
  2910. }
  2911. return rc;
  2912. } //FindObjSymbol
  2913. /***LP PrintBuffData - Print buffer data
  2914. *
  2915. * ENTRY
  2916. * pb -> buffer
  2917. * dwLen - length of buffer
  2918. *
  2919. * EXIT
  2920. * None
  2921. */
  2922. VOID LOCAL PrintBuffData(PUCHAR pb, ULONG dwLen)
  2923. {
  2924. int i, j;
  2925. PRINTF("{");
  2926. for (i = j = 0; i < (int)dwLen; ++i)
  2927. {
  2928. if (j == 0)
  2929. PRINTF("\n\t0x%02x", pb[i]);
  2930. else
  2931. PRINTF(",0x%02x", pb[i]);
  2932. j++;
  2933. if (j >= 14)
  2934. j = 0;
  2935. }
  2936. PRINTF("}");
  2937. } //PrintBuffData
  2938. /***LP PrintSymbol - Print the nearest symbol of a given address
  2939. *
  2940. * ENTRY
  2941. * uip - address
  2942. *
  2943. * EXIT
  2944. * None
  2945. */
  2946. VOID LOCAL PrintSymbol(ULONG_PTR uip)
  2947. {
  2948. ULONG_PTR uipns;
  2949. ULONG dwOffset;
  2950. PRINTF("%08x", uip);
  2951. if (FindObjSymbol(uip, &uipns, &dwOffset))
  2952. {
  2953. PRINTF(":%s", GetObjAddrPath(uipns));
  2954. if (dwOffset != 0)
  2955. {
  2956. PRINTF("+%x", dwOffset);
  2957. }
  2958. }
  2959. } //PrintSymbol
  2960. /***LP EvalExpr - Parse and evaluate debugger expression
  2961. *
  2962. * ENTRY
  2963. * pszArg -> expression argument
  2964. * puipValue -> to hold the result of expression
  2965. * pfPhysical -> set to TRUE if the expression is a physical address
  2966. * (NULL if don't allow physical address)
  2967. * puipns -> to hold the pointer of the nearest pns object
  2968. * pdwOffset -> to hold the offset of the address to the nearest pns object
  2969. *
  2970. * EXIT-SUCCESS
  2971. * returns DBGERR_NONE
  2972. * EXIT-FAILURE
  2973. * returns DBGERR_CMD_FAILED
  2974. */
  2975. LONG LOCAL EvalExpr(PSZ pszArg, PULONG_PTR puipValue, BOOLEAN *pfPhysical,
  2976. PULONG_PTR puipns, PULONG pdwOffset)
  2977. {
  2978. LONG rc = DBGERR_NONE;
  2979. ULONG_PTR uipns = 0;
  2980. ULONG dwOffset = 0;
  2981. NSOBJ NSObj;
  2982. if (pfPhysical != NULL)
  2983. *pfPhysical = FALSE;
  2984. if ((pfPhysical != NULL) && (pszArg[0] == '%') && (pszArg[1] == '%'))
  2985. {
  2986. if (IsNumber(&pszArg[2], 16, puipValue))
  2987. {
  2988. *pfPhysical = TRUE;
  2989. }
  2990. else
  2991. {
  2992. DBG_ERROR(("invalid physical address - %s", pszArg));
  2993. rc = DBGERR_INVALID_CMD;
  2994. }
  2995. }
  2996. else if (!IsNumber(pszArg, 16, puipValue))
  2997. {
  2998. STRUPR(pszArg);
  2999. if (GetNSObj(pszArg, NULL, &uipns, &NSObj,
  3000. NSF_LOCAL_SCOPE | NSF_WARN_NOTFOUND) == DBGERR_NONE)
  3001. {
  3002. if (NSObj.ObjData.dwDataType == OBJTYPE_METHOD)
  3003. {
  3004. *puipValue = (ULONG_PTR)(NSObj.ObjData.pbDataBuff +
  3005. FIELD_OFFSET(METHODOBJ, abCodeBuff));
  3006. }
  3007. else
  3008. {
  3009. DBG_ERROR(("object is not a method - %s", pszArg));
  3010. rc = DBGERR_INVALID_CMD;
  3011. }
  3012. }
  3013. }
  3014. else if (FindObjSymbol(*puipValue, &uipns, &dwOffset))
  3015. {
  3016. if (ReadMemory(uipns, &NSObj, sizeof(NSObj), NULL))
  3017. {
  3018. if ((NSObj.ObjData.dwDataType != OBJTYPE_METHOD) ||
  3019. (dwOffset >= NSObj.ObjData.dwDataLen -
  3020. FIELD_OFFSET(METHODOBJ, abCodeBuff)))
  3021. {
  3022. uipns = 0;
  3023. dwOffset = 0;
  3024. }
  3025. }
  3026. else
  3027. {
  3028. DBG_ERROR(("failed to read NameSpace object at %x", uipns));
  3029. rc = DBGERR_CMD_FAILED;
  3030. }
  3031. }
  3032. if (rc == DBGERR_NONE)
  3033. {
  3034. if (puipns != NULL)
  3035. *puipns = uipns;
  3036. if (pdwOffset != NULL)
  3037. *pdwOffset = dwOffset;
  3038. }
  3039. return rc;
  3040. } //EvalExpr
  3041. /***LP IsNumber - Check if string is a number, if so return the number
  3042. *
  3043. * ENTRY
  3044. * pszStr -> string
  3045. * dwBase - base
  3046. * puipValue -> to hold the number
  3047. *
  3048. * EXIT-SUCCESS
  3049. * returns TRUE - the string is a number
  3050. * EXIT-FAILURE
  3051. * returns FALSE - the string is not a number
  3052. */
  3053. BOOLEAN LOCAL IsNumber(PSZ pszStr, ULONG dwBase, PULONG_PTR puipValue)
  3054. {
  3055. BOOLEAN rc;
  3056. PSZ psz;
  3057. *puipValue = (ULONG_PTR)STRTOUL(pszStr, &psz, dwBase);
  3058. rc = ((psz != pszStr) && (*psz == '\0'))? TRUE: FALSE;
  3059. return rc;
  3060. } //IsNumber
  3061. /***LP AMLITraceEnable - Enable / Disable debug tracing
  3062. *
  3063. * ENTRY
  3064. * fEnable -> TRUE to Enable
  3065. *
  3066. * EXIT-SUCCESS
  3067. * returns DBGERR_NONE
  3068. * EXIT-FAILURE
  3069. * returns DBGERR_CMD_FAILED
  3070. */
  3071. LONG LOCAL AMLITraceEnable(BOOL fEnable)
  3072. {
  3073. LONG rc = DBGERR_NONE;
  3074. ULONG dwData;
  3075. ULONG_PTR uip;
  3076. uip = GetExpression("NT!Kd_AMLI_Mask");
  3077. if (!uip)
  3078. {
  3079. PRINTF("AMLITraceEnable: Could not find NT!Kd_AMLI_Mask\n");
  3080. }
  3081. if(fEnable)
  3082. {
  3083. dwData = 0xffffffff;
  3084. if (!WRITEMEMDWORD(uip, dwData))
  3085. {
  3086. DBG_ERROR(("AMLITraceEnable: failed to write kd_amli_mask at %x", uip));
  3087. rc = DBGERR_CMD_FAILED;
  3088. }
  3089. }
  3090. else
  3091. {
  3092. dwData = 0;
  3093. if (!WRITEMEMDWORD(uip, dwData))
  3094. {
  3095. DBG_ERROR(("AMLITraceEnable: failed to write kd_amli_mask at %x", uip));
  3096. rc = DBGERR_CMD_FAILED;
  3097. }
  3098. }
  3099. return rc;
  3100. }