Ver Fonte

!pdbtest, extra PDB reading robustness

Brian Fiete há 5 anos atrás
pai
commit
c12aea02be
3 ficheiros alterados com 62 adições e 2 exclusões
  1. 20 2
      IDEHelper/COFF.cpp
  2. 1 0
      IDEHelper/COFF.h
  3. 41 0
      IDEHelper/WinDebugger.cpp

+ 20 - 2
IDEHelper/COFF.cpp

@@ -234,6 +234,7 @@ COFF::COFF(DebugTarget* debugTarget) : DbgModule(debugTarget)
 	mCvIPIMaxTag = -1;
 	mMasterCompileUnit = NULL;
 	mTempBufIdx = 0;
+	mIs64Bit = false;
 
 	mCvPageSize = 0;
 	mCvPageBits = 31;
@@ -4891,6 +4892,9 @@ bool COFF::CvParseDBI(int wantAge)
 	BP_ZONE("CvParseDBI");
 		
 	uint8* data = CvReadStream(3);	
+	if (data == NULL)
+		return false;
+
 	uint8* sectionData = data;
 	defer
 	(
@@ -4935,6 +4939,13 @@ bool COFF::CvParseDBI(int wantAge)
 	GET_INTO(uint16, machine);
 	GET_INTO(uint32, reserved); //resvd4
 
+	if (machine == 0x8664)
+		mIs64Bit = true;
+	else if (machine == 0x014C)
+		mIs64Bit = false;
+	else // Unknown machine
+		return false; 
+
 	uint8* headerEnd = data;
 
 	// Skip to debug header
@@ -5023,6 +5034,10 @@ bool COFF::CvParseDBI(int wantAge)
 				BP_ALLOC_T(DbgCompileUnitContrib);
 				auto contribEntry = mAlloc.Alloc<DbgCompileUnitContrib>();
 				contribEntry->mAddress = GetSectionAddr(contrib.mSection, contrib.mOffset) + contribOffset;
+
+				if ((contribEntry->mAddress & 0xFFFF0000'00000000) != 0)
+					continue;
+
 				contribEntry->mLength = curSize;
 				contribEntry->mDbgModule = this;
 				contribEntry->mCompileUnitId = contrib.mModule;
@@ -5560,10 +5575,13 @@ uint8* COFF::HandleSymStreamEntries(CvSymStreamType symStreamType, uint8* data,
 #endif
 
 	if (mIsFastLink)
-		return dataEnd; // FOrmat changed
+		return dataEnd; // Format changed
+
+	if (sizeBuckets == 0)
+		return dataEnd; // No hash
 
 	std::multimap<addr_target, int> checkAddrMap;
-	
+		
 	int bitCount = 0;
 	for (int blockIdx = 0; blockIdx < 0x81; blockIdx++)
 	{

+ 1 - 0
IDEHelper/COFF.h

@@ -222,6 +222,7 @@ public:
 	int mDebugAge;	
 	ParseKind mParseKind;
 	bool mPDBLoaded;
+	bool mIs64Bit;
 
 	int mCvPageSize;
 	int mCvPageBits;

+ 41 - 0
IDEHelper/WinDebugger.cpp

@@ -18,6 +18,7 @@
 #include "BeefySysLib/util/UTF8.h"
 #include "BeefySysLib/FileStream.h"
 #include "BeefySysLib/FileHandleStream.h"
+#include "BeefySysLib/util/FileEnumerator.h"
 #include <inttypes.h>
 #include <windows.h>
 #include "DbgExprEvaluator.h"
@@ -9387,6 +9388,42 @@ void WinDebugger::EvaluateContinueKeep()
 		mDebugPendingExpr->mIdleTicks = 0;
 }
 
+static void PdbTestFile(WinDebugger* debugger, const StringImpl& path)
+{	
+	if (!path.EndsWith(".PDB", StringImpl::CompareKind_OrdinalIgnoreCase))
+		return;
+	
+	OutputDebugStrF("Testing %s\n", path.c_str());
+	COFF coffFile(debugger->mDebugTarget);
+	uint8 wantGuid[16] = { 0 };
+	if (!coffFile.TryLoadPDB(path, wantGuid, -1))
+		return;	
+	if (!coffFile.mIs64Bit)
+		return;	
+	coffFile.ParseTypeData();
+	coffFile.ParseSymbolData();
+	coffFile.ParseGlobalsData();	
+}
+
+static void PdbTest(WinDebugger* debugger, const StringImpl& path)
+{		
+	for (auto& fileEntry : FileEnumerator(path, FileEnumerator::Flags_Files))
+	{
+		String filePath = fileEntry.GetFilePath();
+
+		PdbTestFile(debugger, filePath);
+	}
+
+	for (auto& fileEntry : FileEnumerator(path, FileEnumerator::Flags_Directories))
+	{
+		String childPath = fileEntry.GetFilePath();
+		String dirName;
+		dirName = GetFileName(childPath);
+			
+		PdbTest(debugger, childPath);
+	}	
+}
+
 String WinDebugger::Evaluate(const StringImpl& expr, DwFormatInfo formatInfo, int callStackIdx, int cursorPos, int language, DwEvalExpressionFlags expressionFlags)
 {
 	BP_ZONE_F("WinDebugger::Evaluate %s", BP_DYN_STR(expr.c_str()));
@@ -9471,6 +9508,10 @@ String WinDebugger::Evaluate(const StringImpl& expr, DwFormatInfo formatInfo, in
 				mDbgBreak = true;
 				return "";
 			}
+			else if (cmd == "!pdbtest")
+			{
+				PdbTest(this, "c:\\");
+			}
 		}
 	}