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.

191 lines
4.3 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Handles stepping, tracing, watching and go.
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997-2000.
  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. //----------------------------------------------------------------------------
  41. //
  42. // WatchFunctions.
  43. //
  44. // Collects function information encountered during watch tracing.
  45. //
  46. //----------------------------------------------------------------------------
  47. #define WF_BUCKETS 71
  48. class WatchFunctions
  49. {
  50. public:
  51. WatchFunctions(void);
  52. void Start(void);
  53. void End(PADDR PcAddr);
  54. BOOL IsStarted(void)
  55. {
  56. return m_Started;
  57. }
  58. void OutputFunctions(void);
  59. void OutputSysCallFunctions(void);
  60. WatchFunction* FindAlways(PSTR Sym, ULONG64 Start);
  61. WatchCallStack* GetTopCall(void)
  62. {
  63. return m_CallTop;
  64. }
  65. WatchCallStack* PushCall(WatchFunction* Func);
  66. void PopCall(void);
  67. WatchCallStack* PopCallsToCallSite(PADDR Pc);
  68. WatchCallStack* PopCallsToFunctionStart(ULONG64 Start);
  69. void ReuseCall(WatchCallStack* Call,
  70. WatchFunction* ReinitFunc);
  71. void OutputCall(WatchCallStack* Call);
  72. LONG GetCallLevel(void)
  73. {
  74. return m_CallLevel;
  75. }
  76. LONG ChangeCallLevel(LONG Delta)
  77. {
  78. m_CallLevel += Delta;
  79. if (m_CallLevel < 0)
  80. {
  81. m_CallLevel = 0;
  82. }
  83. return m_CallLevel;
  84. }
  85. ULONG RecordEvent(void)
  86. {
  87. return ++m_TotalWatchTraceEvents;
  88. }
  89. ULONG RecordThreadMismatch(void)
  90. {
  91. return ++m_TotalWatchThreadMismatches;
  92. }
  93. protected:
  94. ULONG Hash(PSTR Sym, ULONG SymLen)
  95. {
  96. // Hash on the first and last letters of the symbol.
  97. return ((ULONG)(UCHAR)Sym[0] +
  98. (ULONG)(UCHAR)Sym[SymLen - 1]) % WF_BUCKETS;
  99. }
  100. WatchFunction* Add(PSTR Sym, ULONG64 Start);
  101. WatchFunction* Find(PSTR Sym);
  102. void Clear(void);
  103. BOOL m_Started;
  104. ULONG m_TotalInstr;
  105. ULONG m_TotalWatchTraceEvents;
  106. ULONG m_TotalWatchThreadMismatches;
  107. WatchFunction* m_Funcs[WF_BUCKETS];
  108. WatchFunction* m_Sorted;
  109. WatchCallStack* m_CallTop, *m_CallBot;
  110. LONG m_CallLevel;
  111. };
  112. extern WatchFunctions g_WatchFunctions;
  113. extern ULONG g_StepTracePassCount;
  114. extern ULONG64 g_StepTraceInRangeStart;
  115. extern ULONG64 g_StepTraceInRangeEnd;
  116. extern BOOL g_SrcLineValid;
  117. extern BOOL g_WatchTrace;
  118. extern BOOL g_WatchWhole;
  119. extern ADDR g_WatchTarget;
  120. extern ULONG64 g_WatchInitialSP;
  121. extern ULONG64 g_WatchBeginCurFunc;
  122. extern ULONG64 g_WatchEndCurFunc;
  123. #define MAX_GO_BPS 16
  124. extern Breakpoint* g_GoBreakpoints[MAX_GO_BPS];
  125. extern ULONG g_NumGoBreakpoints;
  126. BOOL StepTracePass(PADDR);
  127. void
  128. fnGoExecution (
  129. ULONG ExecStatus,
  130. PADDR startaddr,
  131. ULONG bpcount,
  132. PTHREAD_INFO pThread,
  133. BOOL fThreadFreeze,
  134. PADDR bparray
  135. );
  136. void
  137. fnStepTrace (
  138. PADDR addr,
  139. ULONG64 count,
  140. PTHREAD_INFO pThread,
  141. BOOL fThreadFreeze,
  142. UCHAR chStepType
  143. );
  144. void
  145. parseGoCmd (
  146. PTHREAD_INFO pThread,
  147. BOOL fThreadFreeze
  148. );
  149. VOID
  150. parseStepTrace (
  151. PTHREAD_INFO pThread,
  152. BOOL fThreadFreeze,
  153. UCHAR chcmd
  154. );
  155. VOID SetupSpecialCalls(VOID);
  156. #endif // #ifndef _STEPGO_HPP_