HotScanner.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #pragma once
  2. #include "DebugCommon.h"
  3. #include "BeefySysLib/util/HashSet.h"
  4. #include "Debugger.h"
  5. NS_BF_DBG_BEGIN
  6. namespace TCFake
  7. {
  8. struct Span;
  9. static const size_t kPageShift = 13;
  10. static const size_t kNumClasses = 88;
  11. struct PageHeap
  12. {
  13. struct PageMap
  14. {
  15. #ifdef BF_DBG_32
  16. static const int BITS = 32 - kPageShift;
  17. static const int ROOT_BITS = 5;
  18. static const int ROOT_LENGTH = 1 << ROOT_BITS;
  19. static const int LEAF_BITS = BITS - ROOT_BITS;
  20. static const int LEAF_LENGTH = 1 << LEAF_BITS;
  21. struct Leaf
  22. {
  23. addr_target ptrs[LEAF_LENGTH];
  24. };
  25. struct Root
  26. {
  27. addr_target ptrs[ROOT_LENGTH];
  28. };
  29. #else
  30. static const int BITS = 48 - kPageShift;
  31. static const int INTERIOR_BITS = (BITS + 2) / 3; // Round-up
  32. static const int INTERIOR_LENGTH = 1 << INTERIOR_BITS;
  33. static const int LEAF_BITS = BITS - 2 * INTERIOR_BITS;
  34. static const int LEAF_LENGTH = 1 << LEAF_BITS;
  35. struct Node
  36. {
  37. addr_target ptrs[INTERIOR_LENGTH];
  38. };
  39. struct Leaf
  40. {
  41. addr_target ptrs[LEAF_LENGTH];
  42. };
  43. #endif
  44. };
  45. };
  46. }
  47. class WinDebugger;
  48. class DbgSubprogram;
  49. enum BfRtFlags
  50. {
  51. BfRtFlags_ObjectHasDebugFlags = 1,
  52. BfRtFlags_LeakCheck = 2,
  53. BfRtFlags_SilentCrash = 4,
  54. BfRtFlags_DebugAlloc = 8
  55. };
  56. class DbgGCData
  57. {
  58. public:
  59. BfRtFlags mDbgFlags;
  60. addr_target mObjRootPtr;
  61. addr_target mRawRootPtr;
  62. addr_target mRawObjectSentinel;
  63. int mSizeClasses[TCFake::kNumClasses];
  64. };
  65. class DbgHotScanner
  66. {
  67. public:
  68. WinDebugger* mDebugger;
  69. DbgGCData mDbgGCData;
  70. addr_target mBfTypesInfoAddr;
  71. Beefy::Dictionary<addr_target, int> mFoundClassVDataAddrs;
  72. Beefy::Dictionary<addr_target, int> mFoundRawAllocDataAddrs;
  73. Beefy::Dictionary<addr_target, int> mFoundTypeAddrs;
  74. Beefy::HashSet<addr_target> mFoundFuncPtrs;
  75. #ifdef BF_DBG_32
  76. TCFake::PageHeap::PageMap::Root mRoot;
  77. TCFake::PageHeap::PageMap::Leaf mNode;
  78. #else
  79. TCFake::PageHeap::PageMap::Node mRoot;
  80. TCFake::PageHeap::PageMap::Node mNode1;
  81. TCFake::PageHeap::PageMap::Leaf mNode2;
  82. #endif
  83. Beefy::Array<uint8> mScanData;
  84. public:
  85. void AddSubProgram(DbgSubprogram* subProgram, bool followInlineParent, const Beefy::StringImpl& prefix);
  86. void PopulateHotCallstacks();
  87. void ScanSpan(TCFake::Span* span, int expectedStartPage, int memKind);
  88. void ScanRoot(addr_target rootPtr, int memKind);
  89. public:
  90. DbgHotScanner(WinDebugger* debugger);
  91. void Scan(Beefy::DbgHotResolveFlags flags);
  92. };
  93. NS_BF_DBG_END