Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

362 lines
8.9 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Debuggee state buffers.
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999-2002.
  6. //
  7. //----------------------------------------------------------------------------
  8. #ifndef __STATEBUF_H__
  9. #define __STATEBUF_H__
  10. // Different WU_UPDATE qualifiers, sent in WPARAM.
  11. enum UpdateType
  12. {
  13. UPDATE_BUFFER,
  14. UPDATE_BP,
  15. UPDATE_EXEC,
  16. UPDATE_INPUT_REQUIRED,
  17. UPDATE_START_SESSION,
  18. UPDATE_END_SESSION,
  19. UPDATE_PROMPT_TEXT,
  20. UPDATE_EXIT,
  21. UPDATE_REFRESH_MODULES,
  22. UPDATE_REG_NAMES,
  23. };
  24. typedef enum
  25. {
  26. MINVAL_WINDOW = 0,
  27. DOC_WINDOW,
  28. WATCH_WINDOW,
  29. LOCALS_WINDOW,
  30. CPU_WINDOW,
  31. DISASM_WINDOW,
  32. CMD_WINDOW,
  33. SCRATCH_PAD_WINDOW,
  34. MEM_WINDOW,
  35. QUICKW_WINDOW,
  36. CALLS_WINDOW,
  37. PROCESS_THREAD_WINDOW,
  38. MAXVAL_WINDOW,
  39. // Artificial values so there are well-defined bit
  40. // positions for state which is not tied to a specific window.
  41. EVENT_BIT,
  42. BP_BIT,
  43. BP_CMDS_BIT,
  44. FILTER_BIT,
  45. MODULE_BIT,
  46. ALIAS_BIT
  47. } WIN_TYPES, * PWIN_TYPES;
  48. #define FIRST_WINDOW ((WIN_TYPES)(MINVAL_WINDOW + 1))
  49. #define LAST_WINDOW ((WIN_TYPES)(MAXVAL_WINDOW - 1))
  50. #define ALL_WINDOWS 0xffffffff
  51. //----------------------------------------------------------------------------
  52. //
  53. // StateBuffer.
  54. //
  55. // A state buffer is a dynamic container for data passed from
  56. // the engine thread to the UI thread. It may be used for
  57. // holding window content, in which case it will have an HWND
  58. // associated with it, or it can be an internal buffer for non-UI
  59. // purposes.
  60. //
  61. // A list of current window-associated state buffers is kept for
  62. // the engine to traverse when it is updating state for the UI.
  63. // The UI thread is the only thread that can add to this list.
  64. // The engine thread is the only thread that can remove a buffer
  65. // from the list. This is necessary for proper lifetime management
  66. // of dynamically-created buffers.
  67. //
  68. //----------------------------------------------------------------------------
  69. class StateBuffer : public LIST_ENTRY
  70. {
  71. public:
  72. DBG_CRITICAL_SECTION m_Lock;
  73. WIN_TYPES m_enumType;
  74. HWND m_Win;
  75. ULONG m_UpdateTypes;
  76. UpdateType m_UpdateType;
  77. StateBuffer(ULONG ChangeBy);
  78. virtual ~StateBuffer(void);
  79. PVOID AddData(ULONG Len);
  80. BOOL AddString(PCSTR Str, BOOL SoftTerminate);
  81. void RemoveHead(ULONG Len);
  82. void RemoveMiddle(ULONG Start, ULONG Len);
  83. void RemoveTail(ULONG Len);
  84. HRESULT Resize(ULONG Len);
  85. void Free(void);
  86. void Empty(void)
  87. {
  88. m_DataUsed = 0;
  89. }
  90. HRESULT GetStatus(void)
  91. {
  92. return m_Status;
  93. }
  94. void SetStatus(HRESULT Status)
  95. {
  96. m_Status = Status;
  97. }
  98. ULONG GetReadRequest(void)
  99. {
  100. return m_ReadRequest;
  101. }
  102. ULONG GetReadDone(void)
  103. {
  104. return m_ReadDone;
  105. }
  106. void RequestRead(void)
  107. {
  108. InterlockedIncrement((LONG *)&m_ReadRequest);
  109. }
  110. void SetReadDone(ULONG Done)
  111. {
  112. m_ReadDone = Done;
  113. }
  114. PVOID GetDataBuffer(void)
  115. {
  116. return m_Data;
  117. }
  118. ULONG GetDataLen(void)
  119. {
  120. return m_DataUsed;
  121. }
  122. HRESULT Update(void);
  123. void UiRequestRead(void);
  124. HRESULT UiLockForRead(void);
  125. // Base implementation just returns S_OK for
  126. // buffers maintained in other ways.
  127. // ReadState should only be called in the engine thread.
  128. virtual HRESULT ReadState(void);
  129. protected:
  130. void SetNoData(void)
  131. {
  132. m_Data = NULL;
  133. m_DataLen = 0;
  134. Empty();
  135. }
  136. ULONG m_ChangeBy;
  137. UINT m_UpdateMessage;
  138. HRESULT m_Status;
  139. ULONG m_ReadRequest;
  140. ULONG m_ReadDone;
  141. PBYTE m_Data;
  142. ULONG m_DataLen;
  143. ULONG m_DataUsed;
  144. };
  145. //----------------------------------------------------------------------------
  146. //
  147. // OutputToStateBuffer.
  148. //
  149. //----------------------------------------------------------------------------
  150. class OutputToStateBuffer : public DefOutputCallbacks
  151. {
  152. public:
  153. OutputToStateBuffer(void)
  154. {
  155. m_Buffer = NULL;
  156. }
  157. void SetBuffer(StateBuffer* Buffer)
  158. {
  159. m_Buffer = Buffer;
  160. }
  161. HRESULT Start(BOOL Empty);
  162. HRESULT End(BOOL RemoveLastNewLine);
  163. ULONG GetLineCount(void)
  164. {
  165. return m_NewLineCount + m_PartialLine;
  166. }
  167. ULONG RecountLines(void)
  168. {
  169. m_NewLineCount = 0;
  170. AddLines((PSTR)m_Buffer->GetDataBuffer() + m_DataStart);
  171. return GetLineCount();
  172. }
  173. void ReplaceChar(char From, char To);
  174. // IDebugOutputCallbacks.
  175. STDMETHOD(Output)(
  176. THIS_
  177. IN ULONG Mask,
  178. IN PCSTR Text
  179. );
  180. private:
  181. void AddLines(PCSTR Start);
  182. StateBuffer* m_Buffer;
  183. ULONG m_DataStart;
  184. HRESULT m_Status;
  185. ULONG m_NewLineCount;
  186. ULONG m_PartialLine;
  187. };
  188. extern OutputToStateBuffer g_OutStateBuf;
  189. extern OutputToStateBuffer g_UiOutStateBuf;
  190. //----------------------------------------------------------------------------
  191. //
  192. // Dynamic state buffers.
  193. //
  194. //----------------------------------------------------------------------------
  195. extern LIST_ENTRY g_StateList;
  196. // Global lock for short operations where it doesn't matter
  197. // if the threads block on each other briefly. This lock should
  198. // not be held longer than a fraction of a second.
  199. // Used for protecting:
  200. // State buffer list.
  201. // g_Event values.
  202. extern DBG_CRITICAL_SECTION g_QuickLock;
  203. #define LockStateBuffer(Buffer) Dbg_EnterCriticalSection(&(Buffer)->m_Lock)
  204. #define UnlockStateBuffer(Buffer) Dbg_LeaveCriticalSection(&(Buffer)->m_Lock)
  205. #define AssertStateBufferLocked(Buffer) \
  206. Assert(Dbg_CriticalSectionOwned(&(Buffer)->m_Lock))
  207. extern ULONG64 g_CodeIp;
  208. // If g_CodeFileFound[0] == 0 no source file was found.
  209. extern char g_CodeFileFound[];
  210. // If g_CodeSymFile[0] == 0 no source symbol information was found.
  211. extern char g_CodeSymFile[];
  212. extern char g_CodePathComponent[];
  213. extern ULONG g_CodeLine;
  214. extern BOOL g_CodeUserActivated;
  215. extern ULONG g_CodeBufferSequence;
  216. extern ULONG64 g_EventIp;
  217. extern ULONG g_CurSystemId;
  218. extern char g_CurSystemName[];
  219. extern ULONG g_CurProcessId, g_CurProcessSysId;
  220. extern ULONG g_CurThreadId, g_CurThreadSysId;
  221. enum BpStateType
  222. {
  223. BP_ENABLED,
  224. BP_DISABLED,
  225. BP_NONE,
  226. BP_UNKNOWN
  227. };
  228. struct BpBufferData
  229. {
  230. ULONG64 Offset;
  231. ULONG Id;
  232. ULONG Flags;
  233. ULONG Thread;
  234. ULONG Sequence;
  235. ULONG FileOffset;
  236. };
  237. extern ULONG g_BpCount;
  238. extern StateBuffer* g_BpBuffer;
  239. extern ULONG g_BpTextOffset;
  240. extern StateBuffer* g_BpCmdsBuffer;
  241. extern StateBuffer* g_FilterTextBuffer;
  242. extern StateBuffer* g_FilterBuffer;
  243. extern ULONG g_FilterArgsOffset;
  244. extern ULONG g_FilterCmdsOffset;
  245. extern ULONG g_FilterWspCmdsOffset;
  246. extern ULONG g_NumSpecEvents, g_NumSpecEx, g_NumArbEx;
  247. extern StateBuffer* g_ModuleBuffer;
  248. extern ULONG g_NumModules;
  249. extern StateBuffer* g_AliasBuffer;
  250. void FillCodeBuffer(ULONG64 Ip, BOOL UserActivated);
  251. void FillEventBuffer(void);
  252. void ReadStateBuffers(void);
  253. #define BUFFERS_ALL 0xffffffff
  254. void InvalidateStateBuffers(ULONG Types);
  255. void UpdateBufferWindows(ULONG Types, UpdateType Type);
  256. //----------------------------------------------------------------------------
  257. //
  258. // Static state buffers.
  259. //
  260. //----------------------------------------------------------------------------
  261. #define REGCUST_CHANGED_FIRST 0x00000001
  262. #define REGCUST_NO_SUBREG 0x00000002
  263. class RegisterNamesStateBuffer : public StateBuffer
  264. {
  265. public:
  266. RegisterNamesStateBuffer(void)
  267. : StateBuffer(128)
  268. {
  269. m_UpdateTypes = (1 << CPU_WINDOW);
  270. m_UpdateType = UPDATE_REG_NAMES;
  271. m_ProcType = IMAGE_FILE_MACHINE_UNKNOWN;
  272. m_NumRegisters = 0;
  273. m_RegisterMap = NULL;
  274. m_RegisterMapEntries = 0;
  275. m_Flags = 0;
  276. m_NamesOffset = 0;
  277. }
  278. virtual HRESULT ReadState(void);
  279. void GetRegisterMapText(HWND Edit);
  280. void ScanRegisterMapText(HWND Edit);
  281. void SetRegisterMap(ULONG Count, PUSHORT Data);
  282. USHORT MapUserToEngine(ULONG User)
  283. {
  284. return m_RegisterMap != NULL && User < m_RegisterMapEntries ?
  285. m_RegisterMap[User] : (USHORT)User;
  286. }
  287. USHORT MapEngineToUser(ULONG Eng);
  288. ULONG m_ProcType;
  289. ULONG m_NumRegisters;
  290. PUSHORT m_RegisterMap;
  291. ULONG m_RegisterMapEntries;
  292. ULONG m_Flags;
  293. ULONG m_NamesOffset;
  294. };
  295. RegisterNamesStateBuffer* GetRegisterNames(ULONG ProcType);
  296. //----------------------------------------------------------------------------
  297. //
  298. // UI thread state buffer.
  299. //
  300. // The UI thread has simple needs and so one state buffer for
  301. // output capture is sufficient.
  302. //
  303. //----------------------------------------------------------------------------
  304. extern StateBuffer g_UiOutputCapture;
  305. #endif // #ifndef __STATEBUF_H__