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.

362 lines
6.7 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. Vdmtib.c
  5. Abstract:
  6. This module contains routines for manipulating the vdmtib.
  7. Author:
  8. Dave Hastings (daveh) 1-Apr-1992
  9. Notes:
  10. The routines in this module assume that the pointers to the ntsd
  11. routines have already been set up.
  12. Revision History:
  13. --*/
  14. #include <precomp.h>
  15. #pragma hdrstop
  16. #include <stdio.h>
  17. VOID
  18. PrintEventInfo(
  19. IN PVDMEVENTINFO EventInfo
  20. );
  21. VOID
  22. PrintContext(PCONTEXT Context);
  23. ULONG
  24. GetCurrentVdmTib(
  25. VOID
  26. )
  27. /*++
  28. Routine Description:
  29. Retrives the Wx86Tib for a specified thread.
  30. Arguments:
  31. None.
  32. Return Value:
  33. Address of Wx86 (Teb.Vdm) in the debuggee if success
  34. --*/
  35. {
  36. TEB Teb;
  37. NTSTATUS Status;
  38. THREAD_BASIC_INFORMATION ThreadInformation;
  39. ThreadInformation.TebBaseAddress = NULL;
  40. Status = NtQueryInformationThread( hCurrentThread,
  41. ThreadBasicInformation,
  42. &ThreadInformation,
  43. sizeof( ThreadInformation ),
  44. NULL
  45. );
  46. if (!NT_SUCCESS(Status)) {
  47. (*Print)("Unable to get current thread's TEB Status %x\n", Status);
  48. return 0;
  49. }
  50. Status = READMEM(ThreadInformation.TebBaseAddress, &Teb, sizeof(TEB));
  51. if (!NT_SUCCESS(Status)) {
  52. (*Print)("Unable to read TEB %x Status %x\n",
  53. ThreadInformation.TebBaseAddress,
  54. Status
  55. );
  56. return 0;;
  57. }
  58. if ( Teb.Vdm == 0 ) {
  59. (*Print)("Current thread has no vdmtib (Teb.Vdm == NULL) \n"
  60. );
  61. }
  62. return (ULONG)Teb.Vdm;
  63. }
  64. VOID
  65. VdmTibp(
  66. VOID
  67. )
  68. /*++
  69. Routine Description:
  70. This routine dumps out the contents of the register block, and
  71. event info from the vdmtib. If no address is specified (normal case),
  72. then the vdmtib is looked up (symbol VdmTib).
  73. Arguments:
  74. None.
  75. Return Value:
  76. None.
  77. Notes:
  78. This routine assumes that the pointers to the ntsd routines have already
  79. been set up.
  80. --*/
  81. {
  82. BOOL Status;
  83. ULONG Address;
  84. CONTEXT Context;
  85. VDMEVENTINFO EventInfo;
  86. //
  87. // Get the address of the vdmtib
  88. //
  89. if (sscanf(lpArgumentString,"%lx",&Address) <= 0) {
  90. Address = GetCurrentVdmTib();
  91. }
  92. if (!Address) {
  93. (*Print)("Error geting VdmTib address\n");
  94. return;
  95. }
  96. //
  97. // Get the 32 bit context and print it out
  98. //
  99. Status = READMEM(
  100. &(((PVDM_TIB)Address)->MonitorContext),
  101. &Context,
  102. sizeof(CONTEXT)
  103. );
  104. if (!Status) {
  105. GetLastError();
  106. (*Print)("Could not get MonitorContext\n");
  107. } else {
  108. (*Print)("\n32 bit context\n");
  109. PrintContext(&Context);
  110. }
  111. //
  112. // Get the 16 bit context and print it out
  113. //
  114. Status = READMEM(
  115. &(((PVDM_TIB)Address)->VdmContext),
  116. &Context,
  117. sizeof(CONTEXT)
  118. );
  119. if (!Status) {
  120. GetLastError();
  121. (*Print)("Could not get VdmContext\n");
  122. } else {
  123. (*Print)("\n16 bit context\n");
  124. PrintContext(&Context);
  125. }
  126. //
  127. // Get the event info and print it out
  128. //
  129. Status = READMEM(
  130. &(((PVDM_TIB)Address)->EventInfo),
  131. &EventInfo,
  132. sizeof(VDMEVENTINFO)
  133. );
  134. if (!Status) {
  135. GetLastError();
  136. (*Print)("Could not get EventInfo\n");
  137. } else {
  138. (*Print)("\nEvent Info\n");
  139. PrintEventInfo(&EventInfo);
  140. }
  141. }
  142. VOID
  143. EventInfop(
  144. VOID
  145. )
  146. /*++
  147. Routine Description:
  148. This routine dumps the contents of an event info structure. If no
  149. address is specifed (normal case), the event info from the Vdmtib is
  150. dumped.
  151. Arguments:
  152. None.
  153. Return Value:
  154. None.
  155. Notes:
  156. This routine assumes that the pointers to the ntsd routines have already
  157. been set up.
  158. --*/
  159. {
  160. BOOL Status;
  161. ULONG Address;
  162. VDMEVENTINFO EventInfo;
  163. //
  164. // Get the address of the eventinfo
  165. //
  166. if (sscanf(lpArgumentString,"%lx",&Address) <= 0) {
  167. Address = GetCurrentVdmTib();
  168. if (Address) {
  169. Address = (ULONG)(&(((PVDM_TIB)Address)->EventInfo));
  170. }
  171. }
  172. if (!Address) {
  173. (*Print)("Error geting VdmTib address\n");
  174. return;
  175. }
  176. //
  177. // Get the event info and print it out
  178. //
  179. Status = READMEM(
  180. (PVOID)Address,
  181. &EventInfo,
  182. sizeof(VDMEVENTINFO)
  183. );
  184. if (!Status) {
  185. GetLastError();
  186. (*Print)("Could not get EventInfo\n");
  187. } else {
  188. (*Print)("\nEvent Info\n");
  189. PrintEventInfo(&EventInfo);
  190. }
  191. }
  192. VOID
  193. PrintEventInfo(
  194. IN PVDMEVENTINFO EventInfo
  195. )
  196. /*++
  197. Routine Description:
  198. This routine prints out the contents of an event info structure
  199. Arguments:
  200. EventInfo -- Supplies a pointer to the eventinfo
  201. Return Value:
  202. None.
  203. --*/
  204. {
  205. switch (EventInfo->Event) {
  206. case VdmIO :
  207. (*Print)("IO Instruction Event\n");
  208. if (EventInfo->IoInfo.Read) {
  209. (*Print)("Read from ");
  210. } else {
  211. (*Print)("Write to ");
  212. }
  213. switch (EventInfo->IoInfo.Size) {
  214. case 1 :
  215. (*Print)("Byte port ");
  216. break;
  217. case 2 :
  218. (*Print)("Word port ");
  219. break;
  220. case 4 :
  221. (*Print)("Dword port ");
  222. break;
  223. default:
  224. (*Print)("Unknown size port ");
  225. }
  226. (*Print)(" number %x\n", EventInfo->IoInfo.PortNumber);
  227. break;
  228. case VdmStringIO :
  229. (*Print)("String IO Instruction Event\n");
  230. if (EventInfo->StringIoInfo.Read) {
  231. (*Print)("Read from ");
  232. } else {
  233. (*Print)("Write to ");
  234. }
  235. switch (EventInfo->StringIoInfo.Size) {
  236. case 1 :
  237. (*Print)("Byte port ");
  238. break;
  239. case 2 :
  240. (*Print)("Word port ");
  241. break;
  242. case 4 :
  243. (*Print)("Dword port ");
  244. break;
  245. default:
  246. (*Print)("Unknown size port ");
  247. }
  248. (*Print)(" number %x, ", EventInfo->StringIoInfo.PortNumber);
  249. (*Print)(
  250. " Count = %lx, Address = %lx\n",
  251. EventInfo->StringIoInfo.Count,
  252. EventInfo->StringIoInfo.Address
  253. );
  254. break;
  255. case VdmIntAck :
  256. (*Print)("Interrupt Acknowlege Event\n");
  257. break;
  258. case VdmBop:
  259. (*Print)("Bop Event\n");
  260. (*Print)("Bop number %x\n",EventInfo->BopNumber);
  261. break;
  262. case VdmError :
  263. (*Print)("Error Event\n");
  264. (*Print)("Error Status %lx\n",EventInfo->ErrorStatus);
  265. case VdmIrq13 :
  266. (*Print)("IRQ 13 Event\n");
  267. break;
  268. default:
  269. (*Print)("Unknown Event %x\n",EventInfo->Event);
  270. }
  271. }