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.

294 lines
7.1 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Symbol-handling routines.
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997-2002.
  6. //
  7. //----------------------------------------------------------------------------
  8. #ifndef _SYMBOLS_H_
  9. #define _SYMBOLS_H_
  10. typedef enum _DEBUG_SCOPE_STATE
  11. {
  12. ScopeDefault,
  13. ScopeDefaultLazy,
  14. ScopeFromContext,
  15. } DEBUG_SCOPE_STATE;
  16. typedef struct _DEBUG_SCOPE
  17. {
  18. ProcessInfo* Process;
  19. DEBUG_SCOPE_STATE State;
  20. DEBUG_STACK_FRAME Frame;
  21. CROSS_PLATFORM_CONTEXT Context;
  22. ULONG ContextState;
  23. FPO_DATA CachedFpo;
  24. BOOL CheckedForThis;
  25. TypedData ThisData;
  26. } DEBUG_SCOPE, *PDEBUG_SCOPE;
  27. struct SYMBOL_INFO_AND_NAME
  28. {
  29. ULONG64 Raw[(sizeof(SYMBOL_INFO) + MAX_SYMBOL_LEN + sizeof(ULONG64) - 1) /
  30. sizeof(ULONG64)];
  31. PSYMBOL_INFO Init(void)
  32. {
  33. PSYMBOL_INFO Info = (PSYMBOL_INFO)*this;
  34. ZeroMemory(Info, sizeof(*Info));
  35. Info->SizeOfStruct = sizeof(*Info);
  36. Info->MaxNameLen = MAX_SYMBOL_LEN;
  37. return Info;
  38. }
  39. operator PSYMBOL_INFO(void)
  40. {
  41. return (PSYMBOL_INFO)Raw;
  42. }
  43. PSYMBOL_INFO operator->(void)
  44. {
  45. return (PSYMBOL_INFO)Raw;
  46. }
  47. SYMBOL_INFO_AND_NAME(void)
  48. {
  49. Init();
  50. }
  51. };
  52. #define MatchPattern(Str, Pat) \
  53. SymMatchString(Str, Pat, FALSE)
  54. extern PCSTR g_CallConv[];
  55. extern DEBUG_STACK_FRAME g_LastRegFrame;
  56. // The scope buffer is only exposed so that it
  57. // can be looked at without requiring a function call.
  58. // Users of scope information should go through the
  59. // scope abstraction functions.
  60. extern DEBUG_SCOPE g_ScopeBuffer;
  61. extern LPSTR g_SymbolSearchPath;
  62. extern LPSTR g_ExecutableImageSearchPath;
  63. extern ULONG g_SymOptions;
  64. extern PIMAGEHLP_SYMBOL64 g_Sym;
  65. extern SYMBOL_INFO_AND_NAME g_TmpSymInfo;
  66. inline PSTR
  67. ModInfoSymFile(PIMAGEHLP_MODULE64 ModInfo)
  68. {
  69. return ModInfo->LoadedPdbName[0] ? ModInfo->LoadedPdbName :
  70. (ModInfo->LoadedImageName[0] ? ModInfo->LoadedImageName :
  71. ModInfo->ImageName);
  72. }
  73. void RefreshAllModules(BOOL EnsureLines);
  74. HRESULT SetSymOptions(ULONG Options);
  75. void
  76. CreateModuleNameFromPath(
  77. LPSTR szImagePath,
  78. LPSTR szModuleName
  79. );
  80. void
  81. ListNearSymbols(
  82. ULONG64 addrStart
  83. );
  84. BOOL FormatSymbolName(ImageInfo* Image,
  85. ULONG64 Offset,
  86. PCSTR Name,
  87. PULONG64 Displacement,
  88. PSTR Buffer,
  89. ULONG BufferLen);
  90. BOOL GetSymbolInfo(ULONG64 Offset,
  91. PSTR Buffer,
  92. ULONG BufferLen,
  93. PSYMBOL_INFO SymInfo,
  94. PULONG64 Displacement);
  95. BOOL GetNearSymbol(ULONG64 Offset,
  96. PSTR Buffer,
  97. ULONG BufferLen,
  98. PULONG64 Displacement,
  99. LONG Delta);
  100. BOOL GetLineFromAddr(ProcessInfo* Process,
  101. ULONG64 Offset,
  102. PIMAGEHLP_LINE64 Line,
  103. PULONG Displacement);
  104. #define GetSymbol(Offset, Buffer, BufferLen, Displacement) \
  105. GetSymbolInfo(Offset, Buffer, BufferLen, NULL, Displacement)
  106. void OutputSymbolAndInfo(ULONG64 Addr);
  107. BOOL ValidatePathComponent(PCSTR Part);
  108. void SetSymbolSearchPath(ProcessInfo* Process);
  109. void DeferSymbolLoad(ImageInfo*);
  110. void LoadSymbols(ImageInfo*);
  111. void UnloadSymbols(ImageInfo*);
  112. BOOL IgnoreEnumeratedSymbol(ProcessInfo* Process,
  113. PSTR MatchString,
  114. MachineInfo* Machine,
  115. PSYMBOL_INFO SymInfo);
  116. BOOL ForceSymbolCodeAddress(ProcessInfo* Process,
  117. PSYMBOL_INFO Symbol, MachineInfo* Machine);
  118. PCSTR
  119. PrependPrefixToSymbol(char PrefixedString[],
  120. PCSTR pString,
  121. PCSTR *RegString);
  122. BOOL GetOffsetFromBreakpoint(PCSTR String, PULONG64 Offset);
  123. ULONG
  124. GetOffsetFromSym(ProcessInfo* Process,
  125. PCSTR String,
  126. PULONG64 Offset,
  127. ImageInfo** Image);
  128. void
  129. GetAdjacentSymOffsets(ULONG64 AddrStart,
  130. PULONG64 PrevOffset,
  131. PULONG64 NextOffset);
  132. void
  133. GetCurrentMemoryOffsets(
  134. PULONG64 MemoryLow,
  135. PULONG64 MemoryHigh
  136. );
  137. typedef enum _DMT_FLAGS
  138. {
  139. DMT_SYM_IMAGE_FILE_NAME = 0x0000,
  140. DMT_ONLY_LOADED_SYMBOLS = 0x0001,
  141. DMT_ONLY_USER_SYMBOLS = 0x0002,
  142. DMT_ONLY_KERNEL_SYMBOLS = 0x0004,
  143. DMT_VERBOSE = 0x0008,
  144. DMT_SYM_FILE_NAME = 0x0010,
  145. DMT_MAPPED_IMAGE_NAME = 0x0020,
  146. DMT_IMAGE_PATH_NAME = 0x0040,
  147. DMT_IMAGE_TIMESTAMP = 0x0080,
  148. DMT_NO_SYMBOL_OUTPUT = 0x0100,
  149. } DMT_FLAGS;
  150. #define DMT_STANDARD DMT_SYM_FILE_NAME
  151. #define DMT_NAME_FLAGS \
  152. (DMT_SYM_IMAGE_FILE_NAME | DMT_SYM_FILE_NAME | DMT_MAPPED_IMAGE_NAME | \
  153. DMT_IMAGE_PATH_NAME)
  154. enum
  155. {
  156. DMT_NAME_SYM_IMAGE,
  157. DMT_NAME_SYM_FILE,
  158. DMT_NAME_MAPPED_IMAGE,
  159. DMT_NAME_IMAGE_PATH,
  160. DMT_NAME_COUNT
  161. };
  162. void
  163. DumpModuleTable(
  164. ULONG DMT_Flags,
  165. PSTR Pattern
  166. );
  167. void ParseDumpModuleTable(void);
  168. void ParseExamine(void);
  169. BOOL
  170. SymbolCallbackFunction(
  171. HANDLE hProcess,
  172. ULONG ActionCode,
  173. ULONG64 CallbackData,
  174. ULONG64 UserContext
  175. );
  176. BOOL
  177. TranslateAddress(
  178. IN ULONG64 ModBase,
  179. IN ULONG Flags,
  180. IN ULONG RegId,
  181. IN OUT PULONG64 Address,
  182. OUT PULONG64 Value
  183. );
  184. BOOL SetCurrentScope(IN PDEBUG_STACK_FRAME ScopeFrame,
  185. IN OPTIONAL PVOID ScopeContext,
  186. IN ULONG ScopeContextSize);
  187. BOOL ResetCurrentScope(void);
  188. BOOL ResetCurrentScopeLazy(void);
  189. ULONG GetCurrentScopeThisData(TypedData* Data);
  190. inline PDEBUG_SCOPE
  191. GetCurrentScope(void)
  192. {
  193. if (g_ScopeBuffer.State == ScopeDefaultLazy)
  194. {
  195. ResetCurrentScope();
  196. }
  197. return &g_ScopeBuffer;
  198. }
  199. inline PCROSS_PLATFORM_CONTEXT
  200. GetCurrentScopeContext(void)
  201. {
  202. if (g_ScopeBuffer.State == ScopeFromContext)
  203. {
  204. return &g_ScopeBuffer.Context;
  205. }
  206. else
  207. {
  208. return NULL;
  209. }
  210. }
  211. inline PCROSS_PLATFORM_CONTEXT
  212. GetScopeOrMachineContext(void)
  213. {
  214. if (g_ScopeBuffer.State == ScopeFromContext)
  215. {
  216. return &g_ScopeBuffer.Context;
  217. }
  218. else
  219. {
  220. return &g_Machine->m_Context;
  221. }
  222. }
  223. // Force lazy scope to be updated so that actual
  224. // scope data is available.
  225. #define RequireCurrentScope() \
  226. GetCurrentScope()
  227. inline void
  228. PushScope(PDEBUG_SCOPE Buffer)
  229. {
  230. *Buffer = g_ScopeBuffer;
  231. }
  232. inline void
  233. PopScope(PDEBUG_SCOPE Buffer)
  234. {
  235. g_ScopeBuffer = *Buffer;
  236. }
  237. #define LUM_OUTPUT 0x0001
  238. #define LUM_OUTPUT_VERBOSE 0x0002
  239. #define LUM_OUTPUT_TERSE 0x0004
  240. #define LUM_OUTPUT_IMAGE_INFO 0x0008
  241. void ListUnloadedModules(ULONG Flags, PSTR Pattern);
  242. enum
  243. {
  244. FSC_NONE,
  245. FSC_FOUND,
  246. };
  247. ULONG IsInFastSyscall(ULONG64 Addr, PULONG64 Base);
  248. BOOL ShowFunctionParameters(PDEBUG_STACK_FRAME StackFrame);
  249. #endif // #ifndef _SYMBOLS_H_