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.

379 lines
10 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Workspace support.
  4. //
  5. // Copyright (C) Microsoft Corporation, 2000-2001.
  6. //
  7. //----------------------------------------------------------------------------
  8. #ifndef __WRKSPACE_H__
  9. #define __WRKSPACE_H__
  10. //----------------------------------------------------------------------------
  11. //
  12. // A workspace tag is a two-deep tag hierarchy. The group portion
  13. // of the tag allows related items to be collected into a single group.
  14. //
  15. //----------------------------------------------------------------------------
  16. typedef ULONG WSP_TAG;
  17. // Sixteen bits for the group.
  18. #define WSP_GROUP_MASK 0xffff0000
  19. #define WSP_GROUP_SHIFT 16
  20. #define WSP_GROUP_BITS 16
  21. // Sixteen bits for the item.
  22. #define WSP_ITEM_MASK 0x0000ffff
  23. #define WSP_ITEM_SHIFT 0
  24. #define WSP_ITEM_BITS 16
  25. #define WSP_TAG_MASK (WSP_GROUP_MASK | WSP_ITEM_MASK)
  26. #define DEF_WSP_GROUP_TAG(Tag, Group) \
  27. ((Group) << WSP_GROUP_SHIFT)
  28. #define ADD_WSP_ITEM_TAG(Tag, Item) \
  29. ((Tag) | (Item))
  30. #define DEF_WSP_TAG(Group, Item) \
  31. (((Group) << WSP_GROUP_SHIFT) | (Item))
  32. #define WSP_TAG_GROUP(Tag) \
  33. (((Tag) & WSP_GROUP_MASK) >> WSP_GROUP_SHIFT)
  34. #define WSP_TAG_ITEM(Tag) \
  35. (((Tag) & WSP_ITEM_MASK) >> WSP_ITEM_SHIFT)
  36. // Groups.
  37. enum
  38. {
  39. WSP_GROUP_GLOBAL,
  40. WSP_GROUP_WINDOW,
  41. WSP_GROUP_COLORS,
  42. };
  43. // Global group items.
  44. enum
  45. {
  46. WSP_ITEM_SYMBOL_PATH,
  47. WSP_ITEM_IMAGE_PATH,
  48. WSP_ITEM_SOURCE_PATH,
  49. WSP_ITEM_WINDOW_OPTIONS,
  50. WSP_ITEM_REGISTER_MAP,
  51. WSP_ITEM_BREAKPOINTS,
  52. WSP_ITEM_LOG_FILE,
  53. WSP_ITEM_LOCAL_SOURCE_PATH,
  54. WSP_ITEM_FILTERS,
  55. WSP_ITEM_FIXED_LOGFONT,
  56. WSP_ITEM_TAB_WIDTH,
  57. WSP_ITEM_MRU_LIST,
  58. WSP_ITEM_REPEAT_COMMANDS,
  59. WSP_ITEM_COM_SETTINGS,
  60. WSP_ITEM_1394_SETTINGS,
  61. WSP_ITEM_DISASM_ACTIVATE_SOURCE,
  62. WSP_ITEM_VIEW_TOOL_BAR,
  63. WSP_ITEM_VIEW_STATUS_BAR,
  64. WSP_ITEM_AUTO_CMD_SCROLL,
  65. WSP_ITEM_SRC_FILE_PATH,
  66. WSP_ITEM_EXE_COMMAND_LINE,
  67. WSP_ITEM_EXE_CREATE_FLAGS,
  68. WSP_ITEM_DUMP_FILE_NAME,
  69. WSP_ITEM_ATTACH_KERNEL_FLAGS,
  70. WSP_ITEM_TYPE_OPTIONS,
  71. WSP_ITEM_DUMP_FILE_PATH,
  72. WSP_ITEM_EXE_FILE_PATH,
  73. WSP_GLOBAL_COUNT
  74. };
  75. // Window group items.
  76. // The commonwin items exist largely to allow versioning of the window
  77. // information blob. The actual content is determined
  78. // by the implementation of COMMONWIN_DATA::SetWorkspace.
  79. enum
  80. {
  81. WSP_ITEM_COMMONWIN_1,
  82. WSP_ITEM_FRAME_PLACEMENT,
  83. WSP_ITEM_FRAME_TITLE,
  84. WSP_WINDOW_COUNT
  85. };
  86. // Color group items use the color index as the item value.
  87. //
  88. // Specific tags.
  89. //
  90. #define WSP_GLOBAL_SYMBOL_PATH \
  91. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_SYMBOL_PATH)
  92. #define WSP_GLOBAL_IMAGE_PATH \
  93. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_IMAGE_PATH)
  94. #define WSP_GLOBAL_SOURCE_PATH \
  95. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_SOURCE_PATH)
  96. #define WSP_GLOBAL_WINDOW_OPTIONS \
  97. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_WINDOW_OPTIONS)
  98. #define WSP_GLOBAL_REGISTER_MAP \
  99. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_REGISTER_MAP)
  100. #define WSP_GLOBAL_BREAKPOINTS \
  101. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_BREAKPOINTS)
  102. #define WSP_GLOBAL_LOG_FILE \
  103. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_LOG_FILE)
  104. #define WSP_GLOBAL_LOCAL_SOURCE_PATH \
  105. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_LOCAL_SOURCE_PATH)
  106. #define WSP_GLOBAL_FILTERS \
  107. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_FILTERS)
  108. #define WSP_GLOBAL_FIXED_LOGFONT \
  109. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_FIXED_LOGFONT)
  110. #define WSP_GLOBAL_TAB_WIDTH \
  111. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_TAB_WIDTH)
  112. #define WSP_GLOBAL_MRU_LIST \
  113. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_MRU_LIST)
  114. #define WSP_GLOBAL_REPEAT_COMMANDS \
  115. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_REPEAT_COMMANDS)
  116. #define WSP_GLOBAL_COM_SETTINGS \
  117. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_COM_SETTINGS)
  118. #define WSP_GLOBAL_1394_SETTINGS \
  119. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_1394_SETTINGS)
  120. #define WSP_GLOBAL_DISASM_ACTIVATE_SOURCE \
  121. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_DISASM_ACTIVATE_SOURCE)
  122. #define WSP_GLOBAL_VIEW_TOOL_BAR \
  123. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_VIEW_TOOL_BAR)
  124. #define WSP_GLOBAL_VIEW_STATUS_BAR \
  125. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_VIEW_STATUS_BAR)
  126. #define WSP_GLOBAL_AUTO_CMD_SCROLL \
  127. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_AUTO_CMD_SCROLL)
  128. #define WSP_GLOBAL_SRC_FILE_PATH \
  129. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_SRC_FILE_PATH)
  130. #define WSP_GLOBAL_EXE_COMMAND_LINE \
  131. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_EXE_COMMAND_LINE)
  132. #define WSP_GLOBAL_EXE_CREATE_FLAGS \
  133. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_EXE_CREATE_FLAGS)
  134. #define WSP_GLOBAL_DUMP_FILE_NAME \
  135. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_DUMP_FILE_NAME)
  136. #define WSP_GLOBAL_ATTACH_KERNEL_FLAGS \
  137. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_ATTACH_KERNEL_FLAGS)
  138. #define WSP_GLOBAL_TYPE_OPTIONS \
  139. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_TYPE_OPTIONS)
  140. #define WSP_GLOBAL_DUMP_FILE_PATH \
  141. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_DUMP_FILE_PATH)
  142. #define WSP_GLOBAL_EXE_FILE_PATH \
  143. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_EXE_FILE_PATH)
  144. #define WSP_WINDOW_COMMONWIN_1 \
  145. DEF_WSP_TAG(WSP_GROUP_WINDOW, WSP_ITEM_COMMONWIN_1)
  146. #define WSP_WINDOW_FRAME_PLACEMENT \
  147. DEF_WSP_TAG(WSP_GROUP_WINDOW, WSP_ITEM_FRAME_PLACEMENT)
  148. #define WSP_WINDOW_FRAME_TITLE \
  149. DEF_WSP_TAG(WSP_GROUP_WINDOW, WSP_ITEM_FRAME_TITLE)
  150. // Workspace header for window entries.
  151. struct WSP_COMMONWIN_HEADER
  152. {
  153. WIN_TYPES Type;
  154. ULONG Reserved;
  155. };
  156. //----------------------------------------------------------------------------
  157. //
  158. // A workspace is a dynamic buffer of tagged blobs. Values
  159. // are accessed through the Get/Set methods.
  160. //
  161. // Entries are always eight-byte aligned.
  162. //
  163. // Workspaces can be saved and restored from the registry under
  164. // the windbg workspace key.
  165. //
  166. //----------------------------------------------------------------------------
  167. #define WSP_REG_KEY "Software\\Microsoft\\Windbg\\Workspaces"
  168. enum
  169. {
  170. WSP_NAME_BASE,
  171. WSP_NAME_KERNEL,
  172. WSP_NAME_USER,
  173. WSP_NAME_DUMP,
  174. WSP_NAME_REMOTE,
  175. WSP_NAME_EXPLICIT,
  176. WSP_NAME_COUNT
  177. };
  178. #define MAX_WSP_NAME 256
  179. #define WSP_SIGNATURE 'SWDW'
  180. #define WSP_VERSION 1
  181. struct WSP_HEADER
  182. {
  183. ULONG Signature;
  184. ULONG Version;
  185. };
  186. struct WSP_ENTRY
  187. {
  188. WSP_TAG Tag;
  189. USHORT FullSize;
  190. USHORT DataSize;
  191. };
  192. #define WSP_ENTRY_DATA(Type, Entry) ((Type)((Entry) + 1))
  193. #define WSPF_DIRTY_WRITE 0x00000001
  194. #define WSPF_DIRTY_WINDOWS 0x00000002
  195. #define WSPF_DIRTY_BREAKPOINTS 0x00000004
  196. #define WSPF_DIRTY_LOG_FILE 0x00000008
  197. #define WSPF_DIRTY_PATHS 0x00000010
  198. #define WSPF_DIRTY_FILTERS 0x00000020
  199. #define WSPF_DIRTY_MRU_LIST 0x00000040
  200. #define WSPF_DIRTY_ALL 0x0000007f
  201. #define WSP_APPLY_DEFAULT 0x00000000
  202. #define WSP_APPLY_EXPLICIT 0x00000001
  203. #define WSP_APPLY_AGAIN 0x00000002
  204. class Workspace
  205. {
  206. public:
  207. Workspace(void);
  208. ~Workspace(void);
  209. WSP_ENTRY* Get(WSP_TAG Tag);
  210. WSP_ENTRY* GetNext(WSP_ENTRY* Entry, WSP_TAG Tag, WSP_TAG TagMask);
  211. WSP_ENTRY* GetString(WSP_TAG Tag, PSTR Str, ULONG MaxSize);
  212. WSP_ENTRY* GetAllocString(WSP_TAG Tag, PSTR* Str);
  213. WSP_ENTRY* GetBuffer(WSP_TAG Tag, PVOID Buf, ULONG Size);
  214. WSP_ENTRY* GetUlong(WSP_TAG Tag, PULONG Value)
  215. {
  216. return GetBuffer(Tag, Value, sizeof(*Value));
  217. }
  218. WSP_ENTRY* Set(WSP_TAG Tag, ULONG Size);
  219. WSP_ENTRY* SetString(WSP_TAG Tag, PSTR Str);
  220. WSP_ENTRY* SetStrings(WSP_TAG Tag, ULONG Count, PSTR* Strs);
  221. WSP_ENTRY* SetBuffer(WSP_TAG Tag, PVOID Buf, ULONG Size);
  222. WSP_ENTRY* SetUlong(WSP_TAG Tag, ULONG Value)
  223. {
  224. WSP_ENTRY* Entry = SetBuffer(Tag, &Value, sizeof(Value));
  225. return Entry;
  226. }
  227. WSP_ENTRY* Add(WSP_TAG Tag, ULONG Size);
  228. ULONG Delete(WSP_TAG Tag, WSP_TAG TagMask);
  229. void Empty(void);
  230. BOOL IsEmpty(void)
  231. {
  232. return m_DataUsed == sizeof(WSP_HEADER);
  233. }
  234. WSP_HEADER* GetHeader(void)
  235. {
  236. return (WSP_HEADER*)m_Data;
  237. }
  238. BOOL ValidEntry(WSP_ENTRY* Entry)
  239. {
  240. return (PUCHAR)Entry >= m_Data &&
  241. (ULONG)((PUCHAR)Entry - m_Data) < m_DataUsed;
  242. }
  243. WSP_ENTRY* NextEntry(WSP_ENTRY* Entry)
  244. {
  245. if (Entry == NULL)
  246. {
  247. Entry = (WSP_ENTRY*)(m_Data + sizeof(WSP_HEADER));
  248. }
  249. else
  250. {
  251. Entry = (WSP_ENTRY*)((PUCHAR)Entry + Entry->FullSize);
  252. }
  253. if (ValidEntry(Entry))
  254. {
  255. return Entry;
  256. }
  257. else
  258. {
  259. return NULL;
  260. }
  261. }
  262. ULONG GetFlags(void)
  263. {
  264. return m_Flags;
  265. }
  266. void SetFlags(ULONG Flags, ULONG Mask)
  267. {
  268. m_Flags = (m_Flags & ~Mask) | (Flags & Mask);
  269. }
  270. void AddDirty(ULONG Flags)
  271. {
  272. m_Flags |= Flags;
  273. }
  274. void ClearDirty(void)
  275. {
  276. m_Flags &= ~WSPF_DIRTY_ALL;
  277. }
  278. ULONG GetKey(void)
  279. {
  280. return m_Key;
  281. }
  282. PTSTR GetValue(void)
  283. {
  284. return m_Value;
  285. }
  286. static HRESULT Create(ULONG Key, PTSTR Value,
  287. Workspace** NewWsp);
  288. static HRESULT Read(ULONG Key, PTSTR Value,
  289. Workspace** NewWsp);
  290. HRESULT ChangeName(ULONG Key, PTSTR Value, BOOL Force);
  291. HRESULT Flush(BOOL ForceSave, BOOL Cancellable);
  292. void UpdateBreakpointInformation(void);
  293. void UpdateWindowInformation(void);
  294. void UpdateLogFileInformation(void);
  295. void UpdatePathInformation(void);
  296. void UpdateFilterInformation(void);
  297. void UpdateMruListInformation(void);
  298. HRESULT WriteReg(void);
  299. void DeleteReg(BOOL Primary);
  300. static void DeleteRegKey(BOOL Primary, ULONG Key, PTSTR Value);
  301. int Apply(ULONG Flags);
  302. private:
  303. ULONG m_Flags;
  304. PUCHAR m_Data;
  305. ULONG m_DataLen;
  306. ULONG m_DataUsed;
  307. ULONG m_Key;
  308. PTSTR m_Value;
  309. void PackData(PUCHAR Dst, ULONG Len)
  310. {
  311. PUCHAR Src = Dst + Len;
  312. memmove(Dst, Src, m_DataUsed - (ULONG)(Src - m_Data));
  313. m_DataUsed -= Len;
  314. }
  315. WSP_ENTRY* AllocateEntry(ULONG FullSize);
  316. static void GetKeyName(ULONG Key, PSTR KeyName);
  317. static HKEY OpenKey(BOOL Primary, ULONG Key, BOOL Create);
  318. };
  319. // The current workspace.
  320. extern Workspace* g_Workspace;
  321. extern BOOL g_ExplicitWorkspace;
  322. extern char* g_WorkspaceKeyNames[];
  323. extern char* g_WorkspaceDefaultName;
  324. extern char* g_WorkspaceKeyDescriptions[];
  325. HRESULT UiSwitchWorkspace(ULONG Key, PTSTR Value, BOOL Create,
  326. ULONG Flags, int* SessionStarts);
  327. HRESULT UiDelayedSwitchWorkspace(void);
  328. void EngSwitchWorkspace(ULONG Key, PTSTR Value);
  329. PSTR GetWspTagName(WSP_TAG Tag);
  330. #endif // #ifndef __WRKSPACE_H__