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.

516 lines
11 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Engine interface code.
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999-2001.
  6. //
  7. //----------------------------------------------------------------------------
  8. #ifndef __ENGINE_H__
  9. #define __ENGINE_H__
  10. #define RELEASE(Unk) \
  11. ((Unk) != NULL ? ((Unk)->Release(), (Unk) = NULL) : NULL)
  12. #define MAX_ENGINE_PATH 4096
  13. //
  14. // Session initialization parameters.
  15. //
  16. // Turn on verbose output or not.
  17. extern BOOL g_Verbose;
  18. // Dump file to open or NULL.
  19. extern PTSTR g_DumpFile;
  20. extern PTSTR g_DumpPageFile;
  21. // Process server to use.
  22. extern PSTR g_ProcessServer;
  23. // Full command line with exe name.
  24. extern PSTR g_DebugCommandLine;
  25. // Process creation flags.
  26. extern ULONG g_DebugCreateFlags;
  27. // Process ID to attach to or zero.
  28. extern ULONG g_PidToDebug;
  29. // Process name to attach to or NULL.
  30. extern PSTR g_ProcNameToDebug;
  31. extern BOOL g_DetachOnExit;
  32. extern ULONG g_AttachProcessFlags;
  33. // Kernel connection options.
  34. extern ULONG g_AttachKernelFlags;
  35. extern PSTR g_KernelConnectOptions;
  36. // Remoting options.
  37. extern BOOL g_RemoteClient;
  38. extern ULONG g_HistoryLines;
  39. // Type options.
  40. extern ULONG g_TypeOptions;
  41. //
  42. // Debug engine interfaces for the engine thread.
  43. //
  44. extern IDebugClient *g_pDbgClient;
  45. extern IDebugClient2 *g_pDbgClient2;
  46. extern IDebugControl *g_pDbgControl;
  47. extern IDebugSymbols *g_pDbgSymbols;
  48. extern IDebugRegisters *g_pDbgRegisters;
  49. extern IDebugDataSpaces *g_pDbgData;
  50. extern IDebugSystemObjects *g_pDbgSystem;
  51. //
  52. // Debug engine interfaces for the UI thread.
  53. //
  54. extern IDebugClient *g_pUiClient;
  55. extern IDebugControl *g_pUiControl;
  56. extern IDebugSymbols *g_pUiSymbols;
  57. extern IDebugSymbols2 *g_pUiSymbols2;
  58. extern IDebugSystemObjects *g_pUiSystem;
  59. //
  60. // Debug engine interfaces for private output capture.
  61. //
  62. extern IDebugClient *g_pOutCapClient;
  63. extern IDebugControl *g_pOutCapControl;
  64. //
  65. // Debug engine interfaces for local source file lookup.
  66. //
  67. extern IDebugClient *g_pLocClient;
  68. extern IDebugControl *g_pLocControl;
  69. extern IDebugSymbols *g_pLocSymbols;
  70. extern IDebugClient *g_pUiLocClient;
  71. extern IDebugControl *g_pUiLocControl;
  72. extern IDebugSymbols *g_pUiLocSymbols;
  73. extern ULONG g_ActualProcType;
  74. extern char g_ActualProcAbbrevName[32];
  75. extern ULONG g_NumRegisters;
  76. extern ULONG g_CommandSequence;
  77. extern ULONG g_TargetClass;
  78. extern ULONG g_TargetClassQual;
  79. extern BOOL g_Ptr64;
  80. extern ULONG g_ExecStatus;
  81. extern ULONG g_EngOptModified;
  82. extern ULONG g_EngineThreadId;
  83. extern HANDLE g_EngineThread;
  84. extern PSTR g_InitialCommand;
  85. extern char g_PromptText[];
  86. extern BOOL g_WaitingForEvent;
  87. extern BOOL g_SessionActive;
  88. extern ULONG g_NumberRadix;
  89. extern BOOL g_IgnoreCodeLevelChange;
  90. extern ULONG g_LastProcessExitCode;
  91. extern BOOL g_CodeLevelLocked;
  92. // Target exists and is not running.
  93. #define IS_TARGET_HALTED() \
  94. (g_ExecStatus == DEBUG_STATUS_BREAK)
  95. //----------------------------------------------------------------------------
  96. //
  97. // Default output callbacks implementation, provides IUnknown for
  98. // static classes.
  99. //
  100. //----------------------------------------------------------------------------
  101. class DefOutputCallbacks :
  102. public IDebugOutputCallbacks
  103. {
  104. public:
  105. // IUnknown.
  106. STDMETHOD(QueryInterface)(
  107. THIS_
  108. IN REFIID InterfaceId,
  109. OUT PVOID* Interface
  110. );
  111. STDMETHOD_(ULONG, AddRef)(
  112. THIS
  113. );
  114. STDMETHOD_(ULONG, Release)(
  115. THIS
  116. );
  117. };
  118. //----------------------------------------------------------------------------
  119. //
  120. // EventCallbacks.
  121. //
  122. //----------------------------------------------------------------------------
  123. class EventCallbacks : public DebugBaseEventCallbacks
  124. {
  125. public:
  126. // IUnknown.
  127. STDMETHOD_(ULONG, AddRef)(
  128. THIS
  129. );
  130. STDMETHOD_(ULONG, Release)(
  131. THIS
  132. );
  133. // IDebugEventCallbacks.
  134. STDMETHOD(GetInterestMask)(
  135. THIS_
  136. OUT PULONG Mask
  137. );
  138. STDMETHOD(CreateThread)(
  139. THIS_
  140. IN ULONG64 Handle,
  141. IN ULONG64 DataOffset,
  142. IN ULONG64 StartOffset
  143. );
  144. STDMETHOD(ExitThread)(
  145. THIS_
  146. IN ULONG ExitCode
  147. );
  148. STDMETHOD(CreateProcess)(
  149. THIS_
  150. IN ULONG64 ImageFileHandle,
  151. IN ULONG64 Handle,
  152. IN ULONG64 BaseOffset,
  153. IN ULONG ModuleSize,
  154. IN PCSTR ModuleName,
  155. IN PCSTR ImageName,
  156. IN ULONG CheckSum,
  157. IN ULONG TimeDateStamp,
  158. IN ULONG64 InitialThreadHandle,
  159. IN ULONG64 ThreadDataOffset,
  160. IN ULONG64 StartOffset
  161. );
  162. STDMETHOD(ExitProcess)(
  163. THIS_
  164. IN ULONG ExitCode
  165. );
  166. STDMETHOD(SessionStatus)(
  167. THIS_
  168. IN ULONG Status
  169. );
  170. STDMETHOD(ChangeDebuggeeState)(
  171. THIS_
  172. IN ULONG Flags,
  173. IN ULONG64 Argument
  174. );
  175. STDMETHOD(ChangeEngineState)(
  176. THIS_
  177. IN ULONG Flags,
  178. IN ULONG64 Argument
  179. );
  180. STDMETHOD(ChangeSymbolState)(
  181. THIS_
  182. IN ULONG Flags,
  183. IN ULONG64 Argument
  184. );
  185. };
  186. extern EventCallbacks g_EventCb;
  187. //----------------------------------------------------------------------------
  188. //
  189. // Data space read/write support.
  190. //
  191. //----------------------------------------------------------------------------
  192. //
  193. // Begin types originally defined in NTIOAPI.H
  194. //
  195. //
  196. // Define the I/O bus interface types.
  197. //
  198. typedef enum _INTERFACE_TYPE
  199. {
  200. InterfaceTypeUndefined = -1,
  201. Internal,
  202. Isa,
  203. Eisa,
  204. MicroChannel,
  205. TurboChannel,
  206. PCIBus,
  207. VMEBus,
  208. NuBus,
  209. PCMCIABus,
  210. CBus,
  211. MPIBus,
  212. MPSABus,
  213. ProcessorInternal,
  214. InternalPowerBus,
  215. PNPISABus,
  216. PNPBus,
  217. MaximumInterfaceType
  218. } INTERFACE_TYPE, *PINTERFACE_TYPE;
  219. //
  220. // Define types of bus information.
  221. //
  222. typedef enum _BUS_DATA_TYPE
  223. {
  224. ConfigurationSpaceUndefined = -1,
  225. Cmos,
  226. EisaConfiguration,
  227. Pos,
  228. CbusConfiguration,
  229. PCIConfiguration,
  230. VMEConfiguration,
  231. NuBusConfiguration,
  232. PCMCIAConfiguration,
  233. MPIConfiguration,
  234. MPSAConfiguration,
  235. PNPISAConfiguration,
  236. SgiInternalConfiguration,
  237. MaximumBusDataType
  238. } BUS_DATA_TYPE, *PBUS_DATA_TYPE;
  239. //
  240. // End types originally defined in NTIOAPI.H
  241. //
  242. enum MEMORY_TYPE
  243. {
  244. VIRTUAL_MEM_TYPE = 0,
  245. MIN_MEMORY_TYPE = 0, // Placed here so that symbol lookup finds this first
  246. PHYSICAL_MEM_TYPE,
  247. CONTROL_MEM_TYPE,
  248. IO_MEM_TYPE,
  249. MSR_MEM_TYPE,
  250. BUS_MEM_TYPE,
  251. MAX_MEMORY_TYPE
  252. };
  253. struct IO_MEMORY_DATA
  254. {
  255. ULONG BusNumber;
  256. ULONG AddressSpace;
  257. INTERFACE_TYPE interface_type;
  258. };
  259. struct BUS_MEMORY_DATA
  260. {
  261. ULONG BusNumber;
  262. ULONG SlotNumber;
  263. BUS_DATA_TYPE bus_type;
  264. };
  265. struct MSR_MEMORY_DATA
  266. {
  267. // Placeholder in case data is needed later.
  268. };
  269. struct PHYSICAL_MEMORY_DATA
  270. {
  271. // Placeholder in case data is needed later.
  272. };
  273. struct VIRTUAL_MEMORY_DATA
  274. {
  275. // Placeholder in case data is needed later.
  276. };
  277. struct CONTROL_MEMORY_DATA
  278. {
  279. ULONG Processor;
  280. };
  281. struct ANY_MEMORY_DATA
  282. {
  283. union
  284. {
  285. IO_MEMORY_DATA io;
  286. BUS_MEMORY_DATA bus;
  287. MSR_MEMORY_DATA msr;
  288. CONTROL_MEMORY_DATA control;
  289. PHYSICAL_MEMORY_DATA physical;
  290. VIRTUAL_MEMORY_DATA virt;
  291. };
  292. };
  293. //----------------------------------------------------------------------------
  294. //
  295. // Inter-thread communication.
  296. //
  297. // UI buffers are used for transferring information between the
  298. // UI thread and the engine thread, such as commands and output.
  299. // They have a separate lock to avoid contention with state filling.
  300. // If state buffers had individual locks this would be unnecessary.
  301. //
  302. // The UI reads text output from the output buffer for display
  303. // in the command window.
  304. //
  305. // The UI queues commands to the command buffer for execution
  306. // by the engine.
  307. //
  308. //----------------------------------------------------------------------------
  309. // This must be at least MAX_PATH, and also must
  310. // be large enough for the largest single command window
  311. // command expected.
  312. #define MAX_COMMAND_LEN 4096
  313. #define LockUiBuffer(Buffer) Dbg_EnterCriticalSection(&(Buffer)->m_Lock)
  314. #define UnlockUiBuffer(Buffer) Dbg_LeaveCriticalSection(&(Buffer)->m_Lock)
  315. extern class StateBuffer g_UiOutputBuffer;
  316. // Commands from the UI to the engine.
  317. enum UiCommand
  318. {
  319. // Distinguish command input from other commands so
  320. // that the input callbacks have a specific token to
  321. // look for user input.
  322. UIC_CMD_INPUT,
  323. UIC_EXECUTE,
  324. UIC_SILENT_EXECUTE,
  325. UIC_INVISIBLE_EXECUTE,
  326. UIC_SET_REG,
  327. UIC_RESTART,
  328. UIC_END_SESSION,
  329. UIC_WRITE_DATA,
  330. UIC_SYMBOL_WIN,
  331. UIC_DISPLAY_CODE,
  332. UIC_DISPLAY_CODE_EXPR,
  333. UIC_SET_SCOPE,
  334. UIC_GET_SYM_PATH,
  335. UIC_SET_SYM_PATH,
  336. UIC_SET_FILTER,
  337. UIC_SET_FILTER_ARGUMENT,
  338. UIC_SET_FILTER_COMMAND,
  339. };
  340. struct UiCommandData
  341. {
  342. UiCommand Cmd;
  343. ULONG Len;
  344. };
  345. struct UIC_SET_REG_DATA
  346. {
  347. ULONG Reg;
  348. DEBUG_VALUE Val;
  349. };
  350. struct UIC_WRITE_DATA_DATA
  351. {
  352. MEMORY_TYPE Type;
  353. ANY_MEMORY_DATA Any;
  354. ULONG64 Offset;
  355. ULONG Length;
  356. UCHAR Data[16];
  357. };
  358. enum SYMBOL_WIN_CALL_TYPE
  359. {
  360. ADD_SYMBOL_WIN,
  361. DEL_SYMBOL_WIN_INDEX,
  362. DEL_SYMBOL_WIN_NAME,
  363. QUERY_NUM_SYMBOL_WIN,
  364. GET_NAME,
  365. GET_PARAMS,
  366. EXPAND_SYMBOL,
  367. EDIT_SYMBOL,
  368. EDIT_TYPE,
  369. DEL_SYMBOL_WIN_ALL
  370. };
  371. typedef struct UIC_SYMBOL_WIN_DATA
  372. {
  373. SYMBOL_WIN_CALL_TYPE Type;
  374. PDEBUG_SYMBOL_GROUP *pSymbolGroup;
  375. union
  376. {
  377. struct
  378. {
  379. PCSTR Name;
  380. ULONG Index;
  381. } Add;
  382. PCSTR DelName;
  383. ULONG DelIndex;
  384. PULONG NumWatch;
  385. struct
  386. {
  387. ULONG Index;
  388. PSTR Buffer;
  389. ULONG BufferSize;
  390. PULONG NameSize;
  391. } GetName;
  392. struct
  393. {
  394. ULONG Start;
  395. ULONG Count;
  396. PDEBUG_SYMBOL_PARAMETERS SymbolParams;
  397. } GetParams;
  398. struct
  399. {
  400. ULONG Index;
  401. BOOL Expand;
  402. } ExpandSymbol;
  403. struct
  404. {
  405. ULONG Index;
  406. PSTR Value;
  407. } WriteSymbol;
  408. struct
  409. {
  410. ULONG Index;
  411. PSTR Type;
  412. } OutputAsType;
  413. } u;
  414. } UIC_SYMBOL_WIN_DATA;
  415. struct UIC_DISPLAY_CODE_DATA
  416. {
  417. ULONG64 Offset;
  418. };
  419. struct UIC_SET_SCOPE_DATA
  420. {
  421. DEBUG_STACK_FRAME StackFrame;
  422. };
  423. struct UIC_SET_FILTER_DATA
  424. {
  425. ULONG Index;
  426. ULONG Code;
  427. ULONG Execution;
  428. ULONG Continue;
  429. };
  430. struct UIC_SET_FILTER_ARGUMENT_DATA
  431. {
  432. ULONG Index;
  433. char Argument[1];
  434. };
  435. struct UIC_SET_FILTER_COMMAND_DATA
  436. {
  437. ULONG Which;
  438. ULONG Index;
  439. char Command[1];
  440. };
  441. PVOID StartCommand(UiCommand Cmd, ULONG Len);
  442. void FinishCommand(void);
  443. BOOL AddStringCommand(UiCommand Cmd, PCSTR Str);
  444. BOOL AddStringMultiCommand(UiCommand Cmd, PSTR Str);
  445. BOOL __cdecl PrintStringCommand(UiCommand Cmd, PCSTR Format, ...);
  446. #define StartStructCommand(Struct) \
  447. ((Struct ## _DATA*)StartCommand(Struct, sizeof(Struct ## _DATA)))
  448. #define AddEnumCommand(Cmd) \
  449. (StartCommand(Cmd, 0) != NULL ? (FinishCommand(), TRUE) : FALSE)
  450. // Wake up the UI thread to do UI processing.
  451. #define UpdateUi() \
  452. PostMessage(g_hwndFrame, WM_NOTIFY, 0, 0)
  453. // Wake up the engine thread to do engine processing.
  454. void UpdateEngine(void);
  455. void ProcessEngineCommands(BOOL Internal);
  456. void DiscardEngineState(void);
  457. DWORD WINAPI EngineLoop(LPVOID Param);
  458. #endif // #ifndef __ENGINE_H__