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.

500 lines
13 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Global header file.
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999-2002.
  6. //
  7. //----------------------------------------------------------------------------
  8. #ifndef __NTSDP_HPP__
  9. #define __NTSDP_HPP__
  10. #pragma warning(3:4101) // Unreferenced local variable.
  11. // Always turn GUID definitions on. This requires a compiler
  12. // with __declspec(selectany) to compile properly.
  13. #define INITGUID
  14. #include <nt.h>
  15. #include <ntrtl.h>
  16. #include <nturtl.h>
  17. #define STATUS_CPP_EH_EXCEPTION 0xe06d7363
  18. #include <windows.h>
  19. #define _IMAGEHLP64
  20. #include <dbghelp.h>
  21. #include <kdbg1394.h>
  22. #define NOEXTAPI
  23. #include <wdbgexts.h>
  24. #define DEBUG_NO_IMPLEMENTATION
  25. #include <dbgeng.h>
  26. #include <ntdbg.h>
  27. #include "dbgsvc.h"
  28. #include <ntsdexts.h>
  29. #include <vdmdbg.h>
  30. #include <ntiodump.h>
  31. #include <assert.h>
  32. #include <malloc.h>
  33. #include <memory.h>
  34. #include <tchar.h>
  35. #include <stdio.h>
  36. #include <stdlib.h>
  37. #include <crt\io.h>
  38. #include <fcntl.h>
  39. #include <time.h>
  40. #include <math.h>
  41. #undef OVERFLOW
  42. #include <ia64inst.h>
  43. #include <dbhpriv.h>
  44. #include <dbgimage.h>
  45. #include <cmnutil.hpp>
  46. #include <pparse.hpp>
  47. #define NTDLL_APIS
  48. #include <dllimp.h>
  49. #include <cvconst.h>
  50. #include <exdi.h>
  51. #include <dbgeng_exdi_io.h>
  52. typedef ULONG32 mdToken;
  53. typedef mdToken mdMethodDef;
  54. #include <cordac.h>
  55. // Could not go into system header because CRITICAL_SECTION not defined in the
  56. // kernel.
  57. __inline
  58. void
  59. CriticalSection32To64(
  60. IN PRTL_CRITICAL_SECTION32 Cr32,
  61. OUT PRTL_CRITICAL_SECTION64 Cr64
  62. )
  63. {
  64. COPYSE(Cr64,Cr32,DebugInfo);
  65. Cr64->LockCount = Cr32->LockCount;
  66. Cr64->RecursionCount = Cr32->RecursionCount;
  67. COPYSE(Cr64,Cr32,OwningThread);
  68. COPYSE(Cr64,Cr32,LockSemaphore);
  69. COPYSE(Cr64,Cr32,SpinCount);
  70. }
  71. //
  72. // Pointer-size-specific system structures.
  73. //
  74. typedef struct _EXCEPTION_DEBUG_INFO32 {
  75. EXCEPTION_RECORD32 ExceptionRecord;
  76. DWORD dwFirstChance;
  77. } EXCEPTION_DEBUG_INFO32, *LPEXCEPTION_DEBUG_INFO32;
  78. typedef struct _CREATE_THREAD_DEBUG_INFO32 {
  79. ULONG hThread;
  80. ULONG lpThreadLocalBase;
  81. ULONG lpStartAddress;
  82. } CREATE_THREAD_DEBUG_INFO32, *LPCREATE_THREAD_DEBUG_INFO32;
  83. typedef struct _CREATE_PROCESS_DEBUG_INFO32 {
  84. ULONG hFile;
  85. ULONG hProcess;
  86. ULONG hThread;
  87. ULONG lpBaseOfImage;
  88. DWORD dwDebugInfoFileOffset;
  89. DWORD nDebugInfoSize;
  90. ULONG lpThreadLocalBase;
  91. ULONG lpStartAddress;
  92. ULONG lpImageName;
  93. WORD fUnicode;
  94. } CREATE_PROCESS_DEBUG_INFO32, *LPCREATE_PROCESS_DEBUG_INFO32;
  95. typedef struct _EXIT_THREAD_DEBUG_INFO32 {
  96. DWORD dwExitCode;
  97. } EXIT_THREAD_DEBUG_INFO32, *LPEXIT_THREAD_DEBUG_INFO32;
  98. typedef struct _EXIT_PROCESS_DEBUG_INFO32 {
  99. DWORD dwExitCode;
  100. } EXIT_PROCESS_DEBUG_INFO32, *LPEXIT_PROCESS_DEBUG_INFO32;
  101. typedef struct _LOAD_DLL_DEBUG_INFO32 {
  102. ULONG hFile;
  103. ULONG lpBaseOfDll;
  104. DWORD dwDebugInfoFileOffset;
  105. DWORD nDebugInfoSize;
  106. ULONG lpImageName;
  107. WORD fUnicode;
  108. } LOAD_DLL_DEBUG_INFO32, *LPLOAD_DLL_DEBUG_INFO32;
  109. typedef struct _UNLOAD_DLL_DEBUG_INFO32 {
  110. ULONG lpBaseOfDll;
  111. } UNLOAD_DLL_DEBUG_INFO32, *LPUNLOAD_DLL_DEBUG_INFO32;
  112. typedef struct _OUTPUT_DEBUG_STRING_INFO32 {
  113. ULONG lpDebugStringData;
  114. WORD fUnicode;
  115. WORD nDebugStringLength;
  116. } OUTPUT_DEBUG_STRING_INFO32, *LPOUTPUT_DEBUG_STRING_INFO32;
  117. typedef struct _RIP_INFO32 {
  118. DWORD dwError;
  119. DWORD dwType;
  120. } RIP_INFO32, *LPRIP_INFO32;
  121. typedef struct _DEBUG_EVENT32 {
  122. DWORD dwDebugEventCode;
  123. DWORD dwProcessId;
  124. DWORD dwThreadId;
  125. union {
  126. EXCEPTION_DEBUG_INFO32 Exception;
  127. CREATE_THREAD_DEBUG_INFO32 CreateThread;
  128. CREATE_PROCESS_DEBUG_INFO32 CreateProcessInfo;
  129. EXIT_THREAD_DEBUG_INFO32 ExitThread;
  130. EXIT_PROCESS_DEBUG_INFO32 ExitProcess;
  131. LOAD_DLL_DEBUG_INFO32 LoadDll;
  132. UNLOAD_DLL_DEBUG_INFO32 UnloadDll;
  133. OUTPUT_DEBUG_STRING_INFO32 DebugString;
  134. RIP_INFO32 RipInfo;
  135. } u;
  136. } DEBUG_EVENT32, *LPDEBUG_EVENT32;
  137. typedef struct _EXCEPTION_DEBUG_INFO64 {
  138. EXCEPTION_RECORD64 ExceptionRecord;
  139. DWORD dwFirstChance;
  140. } EXCEPTION_DEBUG_INFO64, *LPEXCEPTION_DEBUG_INFO64;
  141. typedef struct _CREATE_THREAD_DEBUG_INFO64 {
  142. ULONG64 hThread;
  143. ULONG64 lpThreadLocalBase;
  144. ULONG64 lpStartAddress;
  145. } CREATE_THREAD_DEBUG_INFO64, *LPCREATE_THREAD_DEBUG_INFO64;
  146. typedef struct _CREATE_PROCESS_DEBUG_INFO64 {
  147. ULONG64 hFile;
  148. ULONG64 hProcess;
  149. ULONG64 hThread;
  150. ULONG64 lpBaseOfImage;
  151. DWORD dwDebugInfoFileOffset;
  152. DWORD nDebugInfoSize;
  153. ULONG64 lpThreadLocalBase;
  154. ULONG64 lpStartAddress;
  155. ULONG64 lpImageName;
  156. WORD fUnicode;
  157. } CREATE_PROCESS_DEBUG_INFO64, *LPCREATE_PROCESS_DEBUG_INFO64;
  158. typedef struct _EXIT_THREAD_DEBUG_INFO64 {
  159. DWORD dwExitCode;
  160. } EXIT_THREAD_DEBUG_INFO64, *LPEXIT_THREAD_DEBUG_INFO64;
  161. typedef struct _EXIT_PROCESS_DEBUG_INFO64 {
  162. DWORD dwExitCode;
  163. } EXIT_PROCESS_DEBUG_INFO64, *LPEXIT_PROCESS_DEBUG_INFO64;
  164. typedef struct _LOAD_DLL_DEBUG_INFO64 {
  165. ULONG64 hFile;
  166. ULONG64 lpBaseOfDll;
  167. DWORD dwDebugInfoFileOffset;
  168. DWORD nDebugInfoSize;
  169. ULONG64 lpImageName;
  170. WORD fUnicode;
  171. } LOAD_DLL_DEBUG_INFO64, *LPLOAD_DLL_DEBUG_INFO64;
  172. typedef struct _UNLOAD_DLL_DEBUG_INFO64 {
  173. ULONG64 lpBaseOfDll;
  174. } UNLOAD_DLL_DEBUG_INFO64, *LPUNLOAD_DLL_DEBUG_INFO64;
  175. typedef struct _OUTPUT_DEBUG_STRING_INFO64 {
  176. ULONG64 lpDebugStringData;
  177. WORD fUnicode;
  178. WORD nDebugStringLength;
  179. } OUTPUT_DEBUG_STRING_INFO64, *LPOUTPUT_DEBUG_STRING_INFO64;
  180. typedef struct _RIP_INFO64 {
  181. DWORD dwError;
  182. DWORD dwType;
  183. } RIP_INFO64, *LPRIP_INFO64;
  184. typedef struct _DEBUG_EVENT64 {
  185. DWORD dwDebugEventCode;
  186. DWORD dwProcessId;
  187. DWORD dwThreadId;
  188. DWORD __alignment;
  189. union {
  190. EXCEPTION_DEBUG_INFO64 Exception;
  191. CREATE_THREAD_DEBUG_INFO64 CreateThread;
  192. CREATE_PROCESS_DEBUG_INFO64 CreateProcessInfo;
  193. EXIT_THREAD_DEBUG_INFO64 ExitThread;
  194. EXIT_PROCESS_DEBUG_INFO64 ExitProcess;
  195. LOAD_DLL_DEBUG_INFO64 LoadDll;
  196. UNLOAD_DLL_DEBUG_INFO64 UnloadDll;
  197. OUTPUT_DEBUG_STRING_INFO64 DebugString;
  198. RIP_INFO64 RipInfo;
  199. } u;
  200. } DEBUG_EVENT64, *LPDEBUG_EVENT64;
  201. #define STATUS_VCPP_EXCEPTION 0x406d1388
  202. #define VCPP_DEBUG_SET_NAME 0x1000
  203. // This structure is passed as the lpArguments field of
  204. // RaiseException so its members need to be decoded out
  205. // of the exception arguments array.
  206. typedef struct tagEXCEPTION_VISUALCPP_DEBUG_INFO32
  207. {
  208. DWORD dwType; // one of the enums from above
  209. union
  210. {
  211. struct
  212. {
  213. DWORD szName; // pointer to name (in user addr space)
  214. DWORD dwThreadID; // thread ID (-1=caller thread)
  215. DWORD dwFlags; // reserved for future use (eg User thread, System thread)
  216. } SetName;
  217. };
  218. } EXCEPTION_VISUALCPP_DEBUG_INFO32;
  219. typedef struct tagEXCEPTION_VISUALCPP_DEBUG_INFO64
  220. {
  221. DWORD dwType; // one of the enums from above
  222. DWORD __alignment;
  223. union
  224. {
  225. struct
  226. {
  227. DWORD64 szName; // pointer to name (in user addr space)
  228. DWORD dwThreadID; // thread ID (-1=caller thread)
  229. DWORD dwFlags; // reserved for future use (eg User thread, System thread)
  230. } SetName;
  231. };
  232. } EXCEPTION_VISUALCPP_DEBUG_INFO64;
  233. //
  234. // Global declarations.
  235. //
  236. #define ENGINE_MOD_NAME "dbgeng"
  237. #define ENGINE_DLL_NAME ENGINE_MOD_NAME ".dll"
  238. #define ARRAYSIZE 20
  239. #define STRLISTSIZE 128
  240. #define MAX_SYMBOL_LEN MAX_SYM_NAME
  241. // Allow space for a symbol, a code address, an EA and other things in
  242. // a line of disassembly.
  243. #define MAX_DISASM_LEN (MAX_SYMBOL_LEN + 128)
  244. #define MAX_THREAD_NAME 32
  245. // Maximum number of bytes possible for a breakpoint instruction.
  246. // Currently sized to hold an entire IA64 bundle plus flags due to
  247. // extraction and insertion considerations.
  248. #define MAX_BREAKPOINT_LENGTH 20
  249. #define MAX_SOURCE_PATH 1024
  250. #define IS_SLASH(Ch) ((Ch) == '/' || (Ch) == '\\')
  251. #define IS_SLASH_W(Ch) ((Ch) == L'/' || (Ch) == L'\\')
  252. #define IS_PATH_DELIM(Ch) (IS_SLASH(Ch) || (Ch) == ':')
  253. #define IS_PATH_DELIM_W(Ch) (IS_SLASH_W(Ch) || (Ch) == L':')
  254. #define IS_EOF(Ch) ((Ch) == 0 || (Ch) == ';')
  255. #define IS_OCTAL_DIGIT(Ch) ((Ch) >= '0' && (Ch) <= '7')
  256. // Maximum command string. DbgPrompt has a limit of 512
  257. // characters so that would be one potential limit. We
  258. // have users who want to use longer command lines, though,
  259. // such as Autodump which scripts the debugger with very long
  260. // sx commands. The other obvious limit is MAX_SYMBOL_LEN
  261. // since it makes sense that you should be able to give a
  262. // command with a full symbol name, so use that.
  263. #define MAX_COMMAND MAX_SYMBOL_LEN
  264. // Maximum length of a full path for an image. Technically
  265. // this can be very large but realistically it's rarely
  266. // greater than MAX_PATH. Use our own constant instead
  267. // of MAX_PATH in case we need to raise it at some point.
  268. // If this constant is increased it's likely that changes
  269. // to dbghelp will be required to increase buffer sizes there.
  270. #define MAX_IMAGE_PATH MAX_PATH
  271. #define BUILD_MAJOR_VERSION (VER_PRODUCTVERSION_W >> 8)
  272. #define BUILD_MINOR_VERSION (VER_PRODUCTVERSION_W & 0xff)
  273. #define BUILD_REVISION API_VERSION_NUMBER
  274. #define KERNEL_MODULE_NAME "nt"
  275. #define KBYTES(Bytes) (((Bytes) + 1023) / 1024)
  276. // Machine type indices for machine-type-indexed things.
  277. enum MachineIndex
  278. {
  279. MACHIDX_I386,
  280. MACHIDX_IA64,
  281. MACHIDX_AMD64,
  282. MACHIDX_ARM,
  283. MACHIDX_COUNT
  284. };
  285. enum
  286. {
  287. OPTFN_ADD,
  288. OPTFN_REMOVE,
  289. OPTFN_SET
  290. };
  291. // Registry keys.
  292. #define DEBUG_ENGINE_KEY "Software\\Microsoft\\Debug Engine"
  293. // Possibly truncates and sign-extends a value to 64 bits.
  294. #define EXTEND64(Val) ((ULONG64)(LONG64)(LONG)(Val))
  295. #define IsPow2(Val) \
  296. (((Val) & ((Val) - 1)) == 0)
  297. enum LAYER
  298. {
  299. LAYER_TARGET,
  300. LAYER_PROCESS,
  301. LAYER_THREAD,
  302. LAYER_COUNT
  303. };
  304. //
  305. // Specific modules.
  306. //
  307. typedef struct _ADDR* PADDR;
  308. typedef struct _DESCRIPTOR64* PDESCRIPTOR64;
  309. class DebugClient;
  310. class TargetInfo;
  311. class MachineInfo;
  312. class ProcessInfo;
  313. class ThreadInfo;
  314. class ImageInfo;
  315. class ModuleInfo;
  316. class UnloadedModuleInfo;
  317. class DbgKdTransport;
  318. struct TypedData;
  319. typedef struct _PENDING_PROCESS* PPENDING_PROCESS;
  320. //
  321. // Segment descriptor values.
  322. // Due to the descriptor caching that x86 processors
  323. // do this may differ from the actual in-memory descriptor and
  324. // may be retrieved in a much different way.
  325. //
  326. #define X86_DESC_TYPE(Flags) ((Flags) & 0x1f)
  327. #define X86_DESC_PRIVILEGE_SHIFT 5
  328. #define X86_DESC_PRIVILEGE(Flags) (((Flags) >> X86_DESC_PRIVILEGE_SHIFT) & 3)
  329. #define X86_DESC_PRESENT 0x80
  330. #define X86_DESC_LONG_MODE 0x200
  331. #define X86_DESC_DEFAULT_BIG 0x400
  332. #define X86_DESC_GRANULARITY 0x800
  333. // Special flags value that marks a descriptor as invalid.
  334. #define SEGDESC_INVALID 0xffffffff
  335. typedef struct _DESCRIPTOR64
  336. {
  337. ULONG64 Base;
  338. ULONG64 Limit;
  339. ULONG Flags;
  340. } DESCRIPTOR64, *PDESCRIPTOR64;
  341. // Maximum value of MAXIMUM_PROCESSORS
  342. #define MAXIMUM_PROCS 64
  343. #include "dbgrpc.hpp"
  344. #include "dotcmd.h"
  345. #include "dbgclt.hpp"
  346. #include "addr.h"
  347. #include "mcache.hpp"
  348. #include "target.hpp"
  349. #include "modinfo.hpp"
  350. #include "image.hpp"
  351. #include "thread.hpp"
  352. #include "process.hpp"
  353. #include "register.h"
  354. #include "machine.hpp"
  355. #include "typedata.hpp"
  356. #include "dbgsym.hpp"
  357. #include "callback.h"
  358. #include "symbols.h"
  359. #include "alias.hpp"
  360. #include "brkpt.hpp"
  361. #include "dbgkdtrans.hpp"
  362. #include "event.h"
  363. #include "expr.hpp"
  364. #include "exts.h"
  365. #include "float10.h"
  366. #include "instr.h"
  367. #include "memcmd.h"
  368. #include "mmap.hpp"
  369. #include "ntcmd.h"
  370. #include "source.h"
  371. #include "symtype.h"
  372. #include "stepgo.hpp"
  373. #include "stkwalk.h"
  374. #include "util.h"
  375. #include "vdm.h"
  376. #include "amd64_reg.h"
  377. #include "arm_reg.h"
  378. #include "i386_reg.h"
  379. #include "ia64_reg.h"
  380. #include "arm_mach.hpp"
  381. #include "i386_mach.hpp"
  382. // Must come after i386_mach.hpp.
  383. #include "amd64_mach.hpp"
  384. #include "ia64_mach.hpp"
  385. // Must come after target.hpp.
  386. #include "dump.hpp"
  387. #include "dbgsvc.hpp"
  388. //
  389. // The Splay function takes as input a pointer to a splay link in a tree
  390. // and splays the tree. Its function return value is a pointer to the
  391. // root of the splayed tree.
  392. //
  393. PRTL_SPLAY_LINKS
  394. pRtlSplay (
  395. PRTL_SPLAY_LINKS Links
  396. );
  397. //
  398. // The Delete function takes as input a pointer to a splay link in a tree
  399. // and deletes that node from the tree. Its function return value is a
  400. // pointer to the root of the tree. If the tree is now empty, the return
  401. // value is NULL.
  402. //
  403. PRTL_SPLAY_LINKS
  404. pRtlDelete (
  405. PRTL_SPLAY_LINKS Links
  406. );
  407. #define EnumerateLocals(CallBack, Context) \
  408. SymEnumSymbols(g_Process->m_SymHandle, \
  409. 0, \
  410. NULL, \
  411. CallBack, \
  412. Context \
  413. )
  414. #endif // ifndef __NTSDP_HPP__