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.

417 lines
12 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Workspace support.
  4. //
  5. // Copyright (C) Microsoft Corporation, 2000-2002.
  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_ITEM_PROC_REGISTER_MAP,
  74. WSP_ITEM_ASSEMBLY_OPTIONS,
  75. WSP_ITEM_EXPRESSION_SYNTAX,
  76. WSP_ITEM_ALIASES,
  77. WSP_ITEM_PROCESS_START_DIR,
  78. WSP_ITEM_PROC_FLAGS_REGISTER_MAP,
  79. WSP_GLOBAL_COUNT
  80. };
  81. // Window group items.
  82. // The commonwin items exist largely to allow versioning of the window
  83. // information blob. The actual content is determined
  84. // by the implementation of COMMONWIN_DATA::SetWorkspace.
  85. enum
  86. {
  87. WSP_ITEM_COMMONWIN_1,
  88. WSP_ITEM_FRAME_PLACEMENT,
  89. WSP_ITEM_FRAME_TITLE,
  90. WSP_WINDOW_COUNT
  91. };
  92. // Color group items use the color index as the item value.
  93. //
  94. // Specific tags.
  95. //
  96. #define WSP_GLOBAL_SYMBOL_PATH \
  97. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_SYMBOL_PATH)
  98. #define WSP_GLOBAL_IMAGE_PATH \
  99. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_IMAGE_PATH)
  100. #define WSP_GLOBAL_SOURCE_PATH \
  101. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_SOURCE_PATH)
  102. #define WSP_GLOBAL_WINDOW_OPTIONS \
  103. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_WINDOW_OPTIONS)
  104. #define WSP_GLOBAL_REGISTER_MAP \
  105. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_REGISTER_MAP)
  106. #define WSP_GLOBAL_BREAKPOINTS \
  107. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_BREAKPOINTS)
  108. #define WSP_GLOBAL_LOG_FILE \
  109. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_LOG_FILE)
  110. #define WSP_GLOBAL_LOCAL_SOURCE_PATH \
  111. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_LOCAL_SOURCE_PATH)
  112. #define WSP_GLOBAL_FILTERS \
  113. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_FILTERS)
  114. #define WSP_GLOBAL_FIXED_LOGFONT \
  115. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_FIXED_LOGFONT)
  116. #define WSP_GLOBAL_TAB_WIDTH \
  117. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_TAB_WIDTH)
  118. #define WSP_GLOBAL_MRU_LIST \
  119. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_MRU_LIST)
  120. #define WSP_GLOBAL_REPEAT_COMMANDS \
  121. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_REPEAT_COMMANDS)
  122. #define WSP_GLOBAL_COM_SETTINGS \
  123. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_COM_SETTINGS)
  124. #define WSP_GLOBAL_1394_SETTINGS \
  125. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_1394_SETTINGS)
  126. #define WSP_GLOBAL_DISASM_ACTIVATE_SOURCE \
  127. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_DISASM_ACTIVATE_SOURCE)
  128. #define WSP_GLOBAL_VIEW_TOOL_BAR \
  129. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_VIEW_TOOL_BAR)
  130. #define WSP_GLOBAL_VIEW_STATUS_BAR \
  131. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_VIEW_STATUS_BAR)
  132. #define WSP_GLOBAL_AUTO_CMD_SCROLL \
  133. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_AUTO_CMD_SCROLL)
  134. #define WSP_GLOBAL_SRC_FILE_PATH \
  135. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_SRC_FILE_PATH)
  136. #define WSP_GLOBAL_EXE_COMMAND_LINE \
  137. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_EXE_COMMAND_LINE)
  138. #define WSP_GLOBAL_EXE_CREATE_FLAGS \
  139. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_EXE_CREATE_FLAGS)
  140. #define WSP_GLOBAL_DUMP_FILE_NAME \
  141. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_DUMP_FILE_NAME)
  142. #define WSP_GLOBAL_ATTACH_KERNEL_FLAGS \
  143. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_ATTACH_KERNEL_FLAGS)
  144. #define WSP_GLOBAL_TYPE_OPTIONS \
  145. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_TYPE_OPTIONS)
  146. #define WSP_GLOBAL_DUMP_FILE_PATH \
  147. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_DUMP_FILE_PATH)
  148. #define WSP_GLOBAL_EXE_FILE_PATH \
  149. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_EXE_FILE_PATH)
  150. #define WSP_GLOBAL_PROC_REGISTER_MAP \
  151. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_PROC_REGISTER_MAP)
  152. #define WSP_GLOBAL_ASSEMBLY_OPTIONS \
  153. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_ASSEMBLY_OPTIONS)
  154. #define WSP_GLOBAL_EXPRESSION_SYNTAX \
  155. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_EXPRESSION_SYNTAX)
  156. #define WSP_GLOBAL_ALIASES \
  157. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_ALIASES)
  158. #define WSP_GLOBAL_PROCESS_START_DIR \
  159. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_PROCESS_START_DIR)
  160. #define WSP_GLOBAL_PROC_FLAGS_REGISTER_MAP \
  161. DEF_WSP_TAG(WSP_GROUP_GLOBAL, WSP_ITEM_PROC_FLAGS_REGISTER_MAP)
  162. #define WSP_WINDOW_COMMONWIN_1 \
  163. DEF_WSP_TAG(WSP_GROUP_WINDOW, WSP_ITEM_COMMONWIN_1)
  164. #define WSP_WINDOW_FRAME_PLACEMENT \
  165. DEF_WSP_TAG(WSP_GROUP_WINDOW, WSP_ITEM_FRAME_PLACEMENT)
  166. #define WSP_WINDOW_FRAME_TITLE \
  167. DEF_WSP_TAG(WSP_GROUP_WINDOW, WSP_ITEM_FRAME_TITLE)
  168. // Workspace header for window entries.
  169. struct WSP_COMMONWIN_HEADER
  170. {
  171. WIN_TYPES Type;
  172. ULONG Reserved;
  173. };
  174. //----------------------------------------------------------------------------
  175. //
  176. // A workspace is a dynamic buffer of tagged blobs. Values
  177. // are accessed through the Get/Set methods.
  178. //
  179. // Entries are always eight-byte aligned.
  180. //
  181. // Workspaces can be saved and restored from the registry under
  182. // the windbg workspace key.
  183. //
  184. //----------------------------------------------------------------------------
  185. #define WSP_REG_KEY "Software\\Microsoft\\Windbg\\Workspaces"
  186. enum
  187. {
  188. // Registry names must come first.
  189. WSP_NAME_BASE,
  190. WSP_NAME_KERNEL,
  191. WSP_NAME_USER,
  192. WSP_NAME_DUMP,
  193. WSP_NAME_REMOTE,
  194. WSP_NAME_EXPLICIT,
  195. WSP_NAME_FILE,
  196. WSP_NAME_COUNT
  197. };
  198. #define WSP_REG_NAME_COUNT (WSP_NAME_EXPLICIT + 1)
  199. #define MAX_WSP_NAME 256
  200. #define WSP_SIGNATURE 'SWDW'
  201. #define WSP_VERSION 1
  202. struct WSP_HEADER
  203. {
  204. ULONG Signature;
  205. ULONG Version;
  206. };
  207. struct WSP_ENTRY
  208. {
  209. WSP_TAG Tag;
  210. USHORT FullSize;
  211. USHORT DataSize;
  212. };
  213. #define WSP_ENTRY_DATA(Type, Entry) ((Type)((Entry) + 1))
  214. #define WSPF_DIRTY_WRITE 0x00000001
  215. #define WSPF_DIRTY_WINDOWS 0x00000002
  216. #define WSPF_DIRTY_BREAKPOINTS 0x00000004
  217. #define WSPF_DIRTY_LOG_FILE 0x00000008
  218. #define WSPF_DIRTY_PATHS 0x00000010
  219. #define WSPF_DIRTY_FILTERS 0x00000020
  220. #define WSPF_DIRTY_MRU_LIST 0x00000040
  221. #define WSPF_DIRTY_ALIASES 0x00000080
  222. #define WSPF_DIRTY_ALL 0x000000ff
  223. #define WSP_APPLY_DEFAULT 0x00000000
  224. #define WSP_APPLY_EXPLICIT 0x00000001
  225. #define WSP_APPLY_AGAIN 0x00000002
  226. enum WSP_CREATE_OPTION
  227. {
  228. WSP_OPEN_EXISTING,
  229. WSP_CREATE_QUERY,
  230. WSP_CREATE_ALWAYS,
  231. };
  232. class Workspace
  233. {
  234. public:
  235. Workspace(void);
  236. ~Workspace(void);
  237. WSP_ENTRY* Get(WSP_TAG Tag);
  238. WSP_ENTRY* GetNext(WSP_ENTRY* Entry, WSP_TAG Tag, WSP_TAG TagMask);
  239. WSP_ENTRY* GetString(WSP_TAG Tag, PSTR Str, ULONG MaxSize);
  240. WSP_ENTRY* GetAllocString(WSP_TAG Tag, PSTR* Str);
  241. WSP_ENTRY* GetBuffer(WSP_TAG Tag, PVOID Buf, ULONG Size);
  242. WSP_ENTRY* GetUlong(WSP_TAG Tag, PULONG Value)
  243. {
  244. return GetBuffer(Tag, Value, sizeof(*Value));
  245. }
  246. WSP_ENTRY* Set(WSP_TAG Tag, ULONG Size);
  247. WSP_ENTRY* SetString(WSP_TAG Tag, PCSTR Str);
  248. WSP_ENTRY* SetStrings(WSP_TAG Tag, ULONG Count, PCSTR* Strs);
  249. WSP_ENTRY* SetBuffer(WSP_TAG Tag, PVOID Buf, ULONG Size);
  250. WSP_ENTRY* SetUlong(WSP_TAG Tag, ULONG Value)
  251. {
  252. WSP_ENTRY* Entry = SetBuffer(Tag, &Value, sizeof(Value));
  253. return Entry;
  254. }
  255. WSP_ENTRY* Add(WSP_TAG Tag, ULONG Size);
  256. void DeleteEntry(WSP_ENTRY* Entry);
  257. ULONG Delete(WSP_TAG Tag, WSP_TAG TagMask);
  258. void Empty(void);
  259. BOOL IsEmpty(void)
  260. {
  261. return m_DataUsed == sizeof(WSP_HEADER);
  262. }
  263. WSP_HEADER* GetHeader(void)
  264. {
  265. return (WSP_HEADER*)m_Data;
  266. }
  267. BOOL ValidEntry(WSP_ENTRY* Entry)
  268. {
  269. return (PUCHAR)Entry >= m_Data &&
  270. (ULONG)((PUCHAR)Entry - m_Data) < m_DataUsed;
  271. }
  272. WSP_ENTRY* NextEntry(WSP_ENTRY* Entry)
  273. {
  274. if (Entry == NULL)
  275. {
  276. Entry = (WSP_ENTRY*)(m_Data + sizeof(WSP_HEADER));
  277. }
  278. else
  279. {
  280. Entry = (WSP_ENTRY*)((PUCHAR)Entry + Entry->FullSize);
  281. }
  282. if (ValidEntry(Entry))
  283. {
  284. return Entry;
  285. }
  286. else
  287. {
  288. return NULL;
  289. }
  290. }
  291. ULONG GetFlags(void)
  292. {
  293. return m_Flags;
  294. }
  295. void SetFlags(ULONG Flags, ULONG Mask)
  296. {
  297. m_Flags = (m_Flags & ~Mask) | (Flags & Mask);
  298. }
  299. void AddDirty(ULONG Flags)
  300. {
  301. m_Flags |= Flags;
  302. }
  303. void ClearDirty(void)
  304. {
  305. m_Flags &= ~WSPF_DIRTY_ALL;
  306. }
  307. ULONG GetKey(void)
  308. {
  309. return m_Key;
  310. }
  311. PTSTR GetValue(void)
  312. {
  313. return m_Value;
  314. }
  315. PTSTR GetName(BOOL Verbose);
  316. HRESULT ReadFromReg(void);
  317. HRESULT ReadFromFile(void);
  318. static HRESULT Create(ULONG Key, PTSTR Value,
  319. Workspace** NewWsp);
  320. static HRESULT Read(ULONG Key, PTSTR Value,
  321. Workspace** NewWsp);
  322. HRESULT ChangeName(ULONG Key, PTSTR Value, BOOL Force);
  323. HRESULT Flush(BOOL ForceSave, BOOL Cancellable);
  324. void UpdateBreakpointInformation(void);
  325. void UpdateWindowInformation(void);
  326. void UpdateLogFileInformation(void);
  327. void UpdatePathInformation(void);
  328. void UpdateFilterInformation(void);
  329. void UpdateMruListInformation(void);
  330. void UpdateAliasInformation(void);
  331. HRESULT WriteToReg(void);
  332. HRESULT WriteToFile(void);
  333. void DeleteReg(BOOL Primary);
  334. static void DeleteRegKey(BOOL Primary, ULONG Key, PTSTR Value);
  335. int Apply(ULONG Flags);
  336. private:
  337. ULONG m_Flags;
  338. PUCHAR m_Data;
  339. ULONG m_DataLen;
  340. ULONG m_DataUsed;
  341. ULONG m_Key;
  342. PTSTR m_Value;
  343. void PackData(PUCHAR Dst, ULONG Len)
  344. {
  345. PUCHAR Src = Dst + Len;
  346. memmove(Dst, Src, m_DataUsed - (ULONG)(Src - m_Data));
  347. m_DataUsed -= Len;
  348. }
  349. WSP_ENTRY* AllocateEntry(ULONG FullSize);
  350. static void GetKeyName(ULONG Key, PSTR KeyName);
  351. static HKEY OpenKey(BOOL Primary, ULONG Key, BOOL Create);
  352. };
  353. // The current workspace.
  354. extern Workspace* g_Workspace;
  355. extern BOOL g_ExplicitWorkspace;
  356. extern char* g_WorkspaceKeyNames[];
  357. extern char* g_WorkspaceDefaultName;
  358. extern char* g_WorkspaceKeyDescriptions[];
  359. HRESULT UiSwitchWorkspace(ULONG Key, PTSTR Value, WSP_CREATE_OPTION Create,
  360. ULONG Flags, int* SessionStarts);
  361. void UiSwitchToExplicitWorkspace(ULONG Key, PTSTR Value);
  362. void UiSaveWorkspaceAs(ULONG Key, PTSTR Value);
  363. HRESULT UiDelayedSwitchWorkspace(void);
  364. void EngSwitchWorkspace(ULONG Key, PTSTR Value);
  365. PSTR GetWspTagName(WSP_TAG Tag);
  366. #endif // #ifndef __WRKSPACE_H__