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.

203 lines
5.0 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Handles stepping, tracing, watching and go.
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997-2002.
  6. //
  7. //----------------------------------------------------------------------------
  8. #ifndef _STEPGO_HPP_
  9. #define _STEPGO_HPP_
  10. struct WatchFunction
  11. {
  12. ULONG64 StartOffset;
  13. // Hash bucket list.
  14. WatchFunction* Next;
  15. // Sorted list.
  16. WatchFunction* Sort;
  17. ULONG Calls;
  18. ULONG MinInstr, MaxInstr, TotalInstr;
  19. // This counter is incremented every time a system call
  20. // instruction is hit inside the function.
  21. ULONG SystemCalls;
  22. // There's no strong need to make this symbol buffer
  23. // MAX_SYMBOL_LEN as the output only displays half a
  24. // line's worth of the name. The only real reason to
  25. // keep more is to reduce false sharing due to prefix
  26. // matches. The buffer is large enough that this should
  27. // be extremely rare, plus we keep the true length
  28. // as a further check.
  29. ULONG SymbolLength;
  30. CHAR Symbol[256];
  31. };
  32. struct WatchCallStack
  33. {
  34. ADDR CallSite;
  35. WatchFunction* Func;
  36. WatchCallStack* Prev, *Next;
  37. LONG Level;
  38. ULONG InstrCount, ChildInstrCount;
  39. };
  40. enum WATCH_CALL_TYPE
  41. {
  42. WCALL_OTHER,
  43. WCALL_CALL,
  44. WCALL_RETURN,
  45. };
  46. //----------------------------------------------------------------------------
  47. //
  48. // WatchFunctions.
  49. //
  50. // Collects function information encountered during watch tracing.
  51. //
  52. //----------------------------------------------------------------------------
  53. #define WF_BUCKETS 71
  54. class WatchFunctions
  55. {
  56. public:
  57. WatchFunctions(void);
  58. void Start(void);
  59. void End(PADDR PcAddr);
  60. BOOL IsStarted(void)
  61. {
  62. return m_Started;
  63. }
  64. void OutputFunctions(void);
  65. void OutputSysCallFunctions(void);
  66. WatchFunction* FindAlways(PSTR Sym, ULONG64 Start);
  67. WatchCallStack* GetTopCall(void)
  68. {
  69. return m_CallTop;
  70. }
  71. WatchCallStack* PushCall(WatchFunction* Func);
  72. void PopCall(void);
  73. WatchCallStack* PopCallsToCallSite(PADDR Pc);
  74. WatchCallStack* PopCallsToFunctionStart(ULONG64 Start);
  75. void ReuseCall(WatchCallStack* Call,
  76. WatchFunction* ReinitFunc);
  77. void IndentForCall(WatchCallStack* Call);
  78. void OutputCall(WatchCallStack* Call, WATCH_CALL_TYPE Type);
  79. void SetDefaultParameters(void);
  80. void ParseParameters(void);
  81. LONG GetCallLevel(void)
  82. {
  83. return m_CallLevel;
  84. }
  85. LONG ChangeCallLevel(LONG Delta)
  86. {
  87. m_CallLevel += Delta;
  88. if (m_CallLevel < 0)
  89. {
  90. m_CallLevel = 0;
  91. }
  92. return m_CallLevel;
  93. }
  94. ULONG RecordEvent(void)
  95. {
  96. return ++m_TotalWatchTraceEvents;
  97. }
  98. ULONG RecordThreadMismatch(void)
  99. {
  100. return ++m_TotalWatchThreadMismatches;
  101. }
  102. LONG m_MaxCallLevelAllowed;
  103. ULONG m_OutputReturnValues:1;
  104. ULONG m_OutputCallAddrs:1;
  105. ULONG m_OutputCalls:1;
  106. ULONG m_OutputSummary:1;
  107. protected:
  108. ULONG Hash(PSTR Sym, ULONG SymLen)
  109. {
  110. // Hash on the first and last letters of the symbol.
  111. return ((ULONG)(UCHAR)Sym[0] +
  112. (ULONG)(UCHAR)Sym[SymLen - 1]) % WF_BUCKETS;
  113. }
  114. WatchFunction* Add(PSTR Sym, ULONG64 Start);
  115. WatchFunction* Find(PSTR Sym);
  116. void Clear(void);
  117. BOOL m_Started;
  118. ULONG m_TotalInstr;
  119. ULONG m_TotalWatchTraceEvents;
  120. ULONG m_TotalWatchThreadMismatches;
  121. WatchFunction* m_Funcs[WF_BUCKETS];
  122. WatchFunction* m_Sorted;
  123. WatchCallStack* m_CallTop, *m_CallBot;
  124. LONG m_CallLevel;
  125. };
  126. extern WatchFunctions g_WatchFunctions;
  127. extern ULONG g_StepTracePassCount;
  128. extern ULONG64 g_StepTraceInRangeStart;
  129. extern ULONG64 g_StepTraceInRangeEnd;
  130. extern BOOL g_SrcLineValid;
  131. extern BOOL g_WatchTrace;
  132. extern BOOL g_WatchWhole;
  133. extern ADDR g_WatchTarget;
  134. extern ULONG64 g_WatchInitialSP;
  135. extern ULONG64 g_WatchBeginCurFunc;
  136. extern ULONG64 g_WatchEndCurFunc;
  137. #define MAX_GO_BPS 16
  138. extern Breakpoint* g_GoBreakpoints[MAX_GO_BPS];
  139. extern ULONG g_NumGoBreakpoints;
  140. void ResetStepTrace(void);
  141. BOOL StepTracePass(PADDR PcAddr);
  142. void
  143. SetExecGo(ULONG ExecStatus,
  144. PADDR StartAddr,
  145. ThreadInfo* Thread,
  146. BOOL ThreadFreeze,
  147. ULONG BpCount,
  148. PADDR BpArray,
  149. PCSTR BpCmd);
  150. void
  151. SetExecStepTrace(PADDR StartAddr,
  152. ULONG64 PassCount,
  153. ThreadInfo* Thread,
  154. BOOL ThreadFreeze,
  155. BOOL ToCall,
  156. char StepType);
  157. void
  158. ParseGoCmd(ThreadInfo* Thread,
  159. BOOL ThreadFreeze);
  160. void ParseStepTrace(ThreadInfo* Thread,
  161. BOOL ThreadFreeze,
  162. char StepType);
  163. VOID SetupSpecialCalls(VOID);
  164. #endif // #ifndef _STEPGO_HPP_