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.

194 lines
3.5 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. All rights reserved.
  4. Module Name:
  5. dumpmem.cxx
  6. Abstract:
  7. Dumps a spllib heap list looking for backtraces.
  8. Author:
  9. Albert Ting (AlbertT) 20-Feb-1995
  10. Revision History:
  11. --*/
  12. #include "precomp.hxx"
  13. #pragma hdrstop
  14. VOID
  15. TDebugExt::
  16. vDumpMem(
  17. LPCSTR pszFile
  18. )
  19. /*++
  20. Routine Description:
  21. Takes an input file of heap blocks and dumps the backtraces.
  22. Arguments:
  23. pszFile - Space terminated input file name.
  24. Return Value:
  25. --*/
  26. {
  27. HANDLE hFile = INVALID_HANDLE_VALUE;
  28. CHAR szFile[MAX_PATH];
  29. LPSTR pcMark;
  30. BOOL bMore = TRUE;
  31. enum {
  32. kLineMax = 0x100
  33. };
  34. //
  35. // Copy & terminate file name.
  36. //
  37. StringCchCopyA( szFile, COUNTOF( szFile ), pszFile);
  38. for( pcMark = szFile;
  39. *pcMark && ( *pcMark != ' ' );
  40. ++pcMark ){
  41. ;
  42. }
  43. //
  44. // If space found, null terminate.
  45. //
  46. if( *pcMark ){
  47. *pcMark = 0;
  48. }
  49. //
  50. // Create the file for reading.
  51. //
  52. hFile = CreateFileA( szFile,
  53. GENERIC_READ,
  54. FILE_SHARE_READ,
  55. NULL,
  56. OPEN_ALWAYS,
  57. 0,
  58. NULL );
  59. if( hFile == INVALID_HANDLE_VALUE ){
  60. Print( "Unable to open file %s\n", szFile );
  61. goto Done;
  62. }
  63. //
  64. // Loop until EOF.
  65. //
  66. while( bMore ){
  67. CHAR szLine[ kLineMax ];
  68. if( CheckControlCRtn()){
  69. Print( "Aborted.\n" );
  70. goto Done;
  71. }
  72. INT i;
  73. //
  74. // Read a line.
  75. //
  76. for( i=0; i< COUNTOF( szLine ) - 1; ++i ){
  77. DWORD dwBytesRead = 0;
  78. BOOL bLeading = TRUE;
  79. ReadFile( hFile,
  80. &szLine[i],
  81. sizeof( szLine[i] ),
  82. &dwBytesRead,
  83. NULL );
  84. if( dwBytesRead != sizeof( szLine[i] )){
  85. goto Done;
  86. }
  87. if( szLine[i] == '\n' ){
  88. break;
  89. }
  90. }
  91. //
  92. // Null terminate.
  93. //
  94. szLine[i] = 0;
  95. LPSTR pszLine;
  96. //
  97. // Remove leading zeros and spaces.
  98. //
  99. for( pszLine = szLine;
  100. *pszLine == ' ' || *pszLine == '0';
  101. ++pszLine ){
  102. ;
  103. }
  104. //
  105. // Terminate at first colon if necessary.
  106. //
  107. for( pcMark = pszLine; *pcMark; ++pcMark ){
  108. if( *pcMark == ':' ){
  109. //
  110. // Null terminate.
  111. //
  112. *pcMark = 0;
  113. break;
  114. }
  115. }
  116. //
  117. // Received line, get address.
  118. //
  119. UINT_PTR Addr = TDebugExt::dwEval( pszLine );
  120. struct SPLLIB_HEADER {
  121. DWORD cbSize;
  122. DWORD AddrBt;
  123. };
  124. SPLLIB_HEADER SpllibHeader;
  125. ZeroMemory( &SpllibHeader, sizeof( SpllibHeader ));
  126. move( SpllibHeader, Addr+8 );
  127. Print( "bt= %x s= %x %x\n\n",
  128. SpllibHeader.AddrBt,
  129. SpllibHeader.cbSize,
  130. Addr );
  131. //
  132. // Dump backtrace.
  133. //
  134. vDumpTrace( SpllibHeader.AddrBt );
  135. Print( "\n" );
  136. }
  137. Done:
  138. if( hFile != INVALID_HANDLE_VALUE ){
  139. CloseHandle( hFile );
  140. }
  141. }