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.

262 lines
10 KiB

  1. typedef HRESULT CALLBACK FNDumpFnCallBack(LPVOID pParam, LPCVOID pvKey, LPCVOID pvRef, LPCVOID pvAddress);
  2. template <class T>
  3. class StlDbgBase : public T
  4. {
  5. public:
  6. static HRESULT HrInitialRead(ULONG64 lpAddress, StlDbgBase<T>** lpHeader);
  7. // Implement these in your derived classes:
  8. static HRESULT HrDumpAllFromUl64(ULONG64 lpAddress, LPVOID lpParam, FNDumpFnCallBack* pFNDumpFnCallBack);
  9. };
  10. //////////////////////////////////////////////////////////////////////////////
  11. //// STL MAP<key, ref> //
  12. //////////////////////////////////////////////////////////////////////////////
  13. template <class T>
  14. class StlDbgMap : public StlDbgBase<T>
  15. {
  16. private:
  17. typedef T::_Imp::_Node _StlDbgNode;
  18. typedef T::_Imp::_Nodeptr _StlDbgNodePtr;
  19. static HRESULT HrDumpAll(LPVOID lpAddress, LPVOID lpParam, FNDumpFnCallBack* pFNDumpFnCallBack);
  20. static HRESULT HrDumpNode(LPVOID pvHead, LPVOID pvDbgHead, DWORD dwLevel, LPVOID lpParam, FNDumpFnCallBack* pFNDumpFnCallBack);
  21. public:
  22. static HRESULT HrDumpAllFromUl64(ULONG64 lpAddress, LPVOID lpParam, FNDumpFnCallBack* pFNDumpFnCallBack);
  23. };
  24. //////////////////////////////////////////////////////////////////////////////
  25. //// STL LIST<ref> //
  26. //////////////////////////////////////////////////////////////////////////////
  27. template <class T>
  28. class StlDbgList : public StlDbgBase<T>
  29. {
  30. private:
  31. typedef T::_Node _StlDbgNode;
  32. typedef T::_Nodeptr _StlDbgNodePtr;
  33. static HRESULT HrDumpAll(LPVOID lpAddress, LPVOID lpParam, FNDumpFnCallBack* pFNDumpFnCallBack);
  34. static HRESULT HrDumpNode(LPVOID pvHead, LPVOID pvDbgHead, DWORD dwLevel, LPVOID lpParam, FNDumpFnCallBack* pFNDumpFnCallBack);
  35. public:
  36. static HRESULT HrDumpAllFromUl64(ULONG64 lpAddress, LPVOID lpParam, FNDumpFnCallBack* pFNDumpFnCallBack);
  37. };
  38. template <class T>
  39. HRESULT StlDbgMap<T>::HrDumpNode(LPVOID pvHead, LPVOID pvDbgHead, DWORD dwLevel, LPVOID lpParam, FNDumpFnCallBack* pFNDumpFnCallBack)
  40. {
  41. _StlDbgNodePtr pHead = reinterpret_cast<_StlDbgNodePtr>(pvHead);
  42. _StlDbgNodePtr pDbgHead = reinterpret_cast<_StlDbgNodePtr>(pvDbgHead);
  43. dprintfVerbose("Dumping node (level %d) from head: [0x%08x]\n", dwLevel, pvDbgHead);
  44. if (!pvDbgHead)
  45. {
  46. return S_FALSE;
  47. }
  48. if ( (!pHead->_Left) && (!pHead->_Right) ) // aparently with the STL version we are using, this identifies an end node.
  49. {
  50. return S_FALSE;
  51. }
  52. HRESULT hr;
  53. hr = pFNDumpFnCallBack(lpParam, &(pHead->_Value.first), &(pHead->_Value.second), &(pDbgHead->_Value));
  54. dprintfVerbose("%d: left is : 0x%08x\n", dwLevel, pHead->_Left);
  55. dprintfVerbose("%d: right is: 0x%08x\n", dwLevel, pHead->_Right);
  56. if (0 != pHead->_Left)
  57. {
  58. _StlDbgNodePtr pNodeLeft = reinterpret_cast<_StlDbgNodePtr>(new BYTE[sizeof(_StlDbgNode)]);
  59. if (pNodeLeft)
  60. {
  61. ZeroMemory(pNodeLeft, sizeof(_StlDbgNodePtr));
  62. dprintfVerbose("%d: Reading left child node ", dwLevel);
  63. hr = HrReadMemory(pHead->_Left, sizeof(_StlDbgNode), pNodeLeft);
  64. if (SUCCEEDED(hr))
  65. {
  66. hr = HrDumpNode(pNodeLeft, pHead->_Left, dwLevel+1, lpParam, pFNDumpFnCallBack);
  67. }
  68. delete [] reinterpret_cast<LPBYTE>(pNodeLeft);
  69. }
  70. }
  71. if (0 != pHead->_Right)
  72. {
  73. _StlDbgNodePtr pNodeRight = reinterpret_cast<_StlDbgNodePtr>(new BYTE[sizeof(_StlDbgNode)]);
  74. if (pNodeRight)
  75. {
  76. ZeroMemory(pNodeRight, sizeof(_StlDbgNode));
  77. dprintfVerbose("%d: Reading right child node ", dwLevel);
  78. hr = HrReadMemory(pHead->_Right, sizeof(_StlDbgNode), pNodeRight);
  79. if (SUCCEEDED(hr))
  80. {
  81. hr = HrDumpNode(pNodeRight, pHead->_Right, dwLevel+1, lpParam, pFNDumpFnCallBack);
  82. }
  83. delete [] reinterpret_cast<LPBYTE>(pNodeRight);
  84. }
  85. }
  86. return S_OK;
  87. }
  88. template <class T>
  89. HRESULT StlDbgMap<T>::HrDumpAll(LPVOID lpAddress, LPVOID lpParam, FNDumpFnCallBack* pFNDumpFnCallBack)
  90. {
  91. return HrDumpAllFromUl64((ULONG64)(ULONG_PTR)(lpAddress), lpParam, pFNDumpFnCallBack);
  92. }
  93. template <class T>
  94. HRESULT StlDbgList<T>::HrDumpAll(LPVOID lpAddress, LPVOID lpParam, FNDumpFnCallBack* pFNDumpFnCallBack)
  95. {
  96. return HrDumpAllFromUl64((ULONG64)(ULONG_PTR)(lpAddress), lpParam, pFNDumpFnCallBack);
  97. }
  98. template <class T>
  99. HRESULT StlDbgMap<T>::HrDumpAllFromUl64(ULONG64 lpAddress, LPVOID lpParam, FNDumpFnCallBack* pFNDumpFnCallBack)
  100. {
  101. HRESULT hr = E_FAIL;
  102. C_ASSERT(sizeof(T) == sizeof(StlDbgMap<T>)); // If you have a compile error on this line it means you added non-static data to your class.
  103. // This is not allowed as it will break the binary compatibility of the structure.
  104. StlDbgMap<T> *pStlDbgCore;
  105. hr = HrInitialRead(lpAddress, reinterpret_cast<StlDbgBase<T> **>(&pStlDbgCore));
  106. if (S_OK == hr) // don't care if 0 entries
  107. {
  108. _StlDbgNodePtr pStlDbgHeadNode = reinterpret_cast<_StlDbgNodePtr>(new BYTE[sizeof(_StlDbgNode)]);
  109. if (pStlDbgHeadNode)
  110. {
  111. ZeroMemory(pStlDbgHeadNode, sizeof(_StlDbgNode));
  112. dprintfVerbose("Reading map<>.[_Tr]._Head");
  113. hr = HrReadMemory(pStlDbgCore->_Tr._Head, sizeof(_StlDbgNode), pStlDbgHeadNode);
  114. if (SUCCEEDED(hr))
  115. {
  116. _StlDbgNodePtr pDbgMapRootNode = reinterpret_cast<_StlDbgNodePtr>(new BYTE[sizeof(_StlDbgNode)]);
  117. if (pDbgMapRootNode)
  118. {
  119. ZeroMemory(pDbgMapRootNode, sizeof(_StlDbgNode));
  120. dprintfVerbose("Reading map<>.[_Tr]._Head._Parent");
  121. hr = HrReadMemory( pStlDbgHeadNode->_Parent, sizeof(_StlDbgNode), pDbgMapRootNode);
  122. if (SUCCEEDED(hr))
  123. {
  124. hr = HrDumpNode(pDbgMapRootNode, pStlDbgHeadNode->_Parent, 0, lpParam, pFNDumpFnCallBack);
  125. }
  126. delete [] reinterpret_cast<LPBYTE>(pDbgMapRootNode);
  127. }
  128. }
  129. delete [] reinterpret_cast<LPBYTE>(pStlDbgHeadNode);
  130. }
  131. delete reinterpret_cast<LPBYTE>(pStlDbgCore);
  132. }
  133. return hr;
  134. }
  135. template <class T>
  136. HRESULT StlDbgList<T>::HrDumpAllFromUl64(ULONG64 lpAddress, LPVOID lpParam, FNDumpFnCallBack* pFNDumpFnCallBack)
  137. {
  138. HRESULT hr = E_FAIL;
  139. C_ASSERT(sizeof(T) == sizeof(StlDbgList<T>)); // If you have a compile error on this line it means you added non-static data to your class.
  140. // This is not allowed as it will break the binary compatibility of the structure.
  141. StlDbgList<T> *pStlDbgCore;
  142. hr = HrInitialRead(lpAddress, reinterpret_cast<StlDbgBase<T> **>(&pStlDbgCore));
  143. if (S_OK == hr) // don't care if 0 entries
  144. {
  145. _StlDbgNodePtr pStlDbgHeadNode = reinterpret_cast<_StlDbgNodePtr>(new BYTE[sizeof(_StlDbgNode)]);
  146. if (pStlDbgHeadNode)
  147. {
  148. ZeroMemory(pStlDbgHeadNode, sizeof(_StlDbgNode));
  149. dprintfVerbose("Reading list<>._Head");
  150. hr = HrReadMemory(pStlDbgCore->_Head, sizeof(_StlDbgNode), pStlDbgHeadNode);
  151. if (SUCCEEDED(hr))
  152. {
  153. _StlDbgNodePtr pStlDbgNodeNext = reinterpret_cast<_StlDbgNodePtr>(new BYTE[sizeof(_StlDbgNode)]);
  154. if (pStlDbgNodeNext)
  155. {
  156. BOOL fDone = FALSE;
  157. dprintfVerbose("Reading list<>._Head->_Next");
  158. hr = HrReadMemory(pStlDbgHeadNode->_Next, sizeof(_StlDbgNode), pStlDbgNodeNext);
  159. LPVOID ulReadAddress = pStlDbgNodeNext->_Value;
  160. while (SUCCEEDED(hr) && !fDone)
  161. {
  162. dprintfVerbose("dumping list entry at from 0x%08x\r\n", pStlDbgNodeNext->_Value);
  163. hr = pFNDumpFnCallBack(lpParam, NULL, pStlDbgNodeNext->_Value, ulReadAddress);
  164. if (SUCCEEDED(hr))
  165. {
  166. if (pStlDbgNodeNext->_Next == pStlDbgCore->_Head)
  167. {
  168. dprintfVerbose("end of list\n");
  169. fDone = TRUE;
  170. }
  171. else
  172. {
  173. hr = HrReadMemory(pStlDbgNodeNext->_Next, sizeof(_StlDbgNode), pStlDbgNodeNext);
  174. ulReadAddress = pStlDbgNodeNext->_Value;
  175. }
  176. }
  177. }
  178. }
  179. }
  180. delete [] reinterpret_cast<LPBYTE>(pStlDbgHeadNode);
  181. }
  182. delete reinterpret_cast<LPBYTE>(pStlDbgCore);
  183. }
  184. return hr;
  185. }
  186. template <class T>
  187. HRESULT StlDbgBase<T>::HrInitialRead(ULONG64 lpAddress, StlDbgBase<T>** lpHeader)
  188. {
  189. HRESULT hr = E_FAIL;
  190. C_ASSERT(sizeof(T) == sizeof(StlDbgBase<T>));// If you have a compile error on this line it means you added non-static data to your class.
  191. // This is not allowed as it will break the binary compatibility of the structure.
  192. StlDbgBase<T> *pStlDbgCore = reinterpret_cast<StlDbgBase<T> *>(new BYTE[sizeof(StlDbgBase<T>)]);
  193. if (pStlDbgCore)
  194. {
  195. ZeroMemory(pStlDbgCore, sizeof(StlDbgBase<T>));
  196. dprintfVerbose("Reading STL class starting at %08x", lpAddress);
  197. hr = HrReadMemoryFromUlong(lpAddress, sizeof(StlDbgBase<T>), pStlDbgCore);
  198. if (SUCCEEDED(hr))
  199. {
  200. dprintf("%d entries found:\n", pStlDbgCore->size());
  201. if (pStlDbgCore->size())
  202. {
  203. hr = S_OK;
  204. }
  205. else
  206. {
  207. hr = S_FALSE;
  208. }
  209. }
  210. if (SUCCEEDED(hr))
  211. {
  212. *lpHeader = pStlDbgCore;
  213. }
  214. else
  215. {
  216. delete reinterpret_cast<LPBYTE>(pStlDbgCore);
  217. }
  218. }
  219. return hr;
  220. }