mirror of
https://github.com/beefytech/Beef.git
synced 2025-07-06 16:25:59 +02:00
Added MD5 file hashes to Beef
This commit is contained in:
parent
32c09bf94b
commit
61468d818f
33 changed files with 598 additions and 143 deletions
|
@ -1635,6 +1635,21 @@ void BeCOFFObject::DbgGenerateModuleInfo()
|
|||
}
|
||||
}
|
||||
|
||||
Array<int> fileDataPositions;
|
||||
///
|
||||
{
|
||||
int fileDataPos = 0;
|
||||
for (auto dbgFile : mBeModule->mDbgModule->mFiles)
|
||||
{
|
||||
fileDataPositions.Add(fileDataPos);
|
||||
fileDataPos += 4;
|
||||
if (dbgFile->mMD5Hash.IsZero())
|
||||
fileDataPos += 4;
|
||||
else
|
||||
fileDataPos += 20;
|
||||
}
|
||||
}
|
||||
|
||||
int emissionStartIdx = 0;
|
||||
BeDbgFile* curDbgFile = NULL;
|
||||
for (int emissionIdx = 0; emissionIdx < (int)emissions.size(); emissionIdx++)
|
||||
|
@ -1657,7 +1672,7 @@ void BeCOFFObject::DbgGenerateModuleInfo()
|
|||
curDbgFile = dbgFile;
|
||||
|
||||
lastBlockStartPos = outS.GetPos();
|
||||
outS.Write((int32)dbgFile->mIdx * 8);
|
||||
outS.Write((int32)fileDataPositions[dbgFile->mIdx]);
|
||||
outS.Write((int32)0); // placeholder nLines
|
||||
outS.Write((int32)0); // placeholder cbBlock
|
||||
|
||||
|
@ -1779,7 +1794,19 @@ void BeCOFFObject::DbgGenerateModuleInfo()
|
|||
for (auto dbgFile : mBeModule->mDbgModule->mFiles)
|
||||
{
|
||||
outS.Write((int32)strTable.size());
|
||||
outS.Write((int32)0); // hashLen, hashType, padding
|
||||
|
||||
if (dbgFile->mMD5Hash.IsZero())
|
||||
{
|
||||
outS.Write((int32)0); // hashLen, hashType, padding
|
||||
}
|
||||
else
|
||||
{
|
||||
outS.Write((uint8)16); // hashLen
|
||||
outS.Write((uint8)1); // hashType
|
||||
outS.Write(&dbgFile->mMD5Hash, 16);
|
||||
outS.Write((int8)0); // padding
|
||||
outS.Write((int8)0);
|
||||
}
|
||||
|
||||
String fullPath;
|
||||
dbgFile->ToString(fullPath);
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "BeefySysLib/util/BeefPerf.h"
|
||||
|
||||
#include "BeefySysLib/util/AllocDebug.h"
|
||||
#include "BeefySysLib/util/Hash.h"
|
||||
|
||||
USING_NS_BF;
|
||||
|
||||
|
@ -518,6 +519,12 @@ void BeIRCodeGen::Read(int64& i)
|
|||
BE_MEM_END("int64");
|
||||
}
|
||||
|
||||
void BeIRCodeGen::Read(Val128& i)
|
||||
{
|
||||
i.mLow = (uint64)ReadSLEB128();
|
||||
i.mHigh = (uint64)ReadSLEB128();
|
||||
}
|
||||
|
||||
void BeIRCodeGen::Read(bool& val)
|
||||
{
|
||||
BE_MEM_START;
|
||||
|
@ -2362,10 +2369,12 @@ void BeIRCodeGen::HandleNextCmd()
|
|||
{
|
||||
CMD_PARAM(String, fileName);
|
||||
CMD_PARAM(String, directory);
|
||||
CMD_PARAM(Val128, md5Hash);
|
||||
|
||||
auto dbgFile = mBeModule->mDbgModule->mFiles.Alloc();
|
||||
dbgFile->mFileName = fileName;
|
||||
dbgFile->mFileName = fileName;
|
||||
dbgFile->mDirectory = directory;
|
||||
dbgFile->mMD5Hash = md5Hash;
|
||||
dbgFile->mIdx = (int)mBeModule->mDbgModule->mFiles.size() - 1;
|
||||
|
||||
SetResult(curId, dbgFile);
|
||||
|
|
|
@ -95,6 +95,7 @@ public:
|
|||
void Read(StringImpl& str);
|
||||
void Read(int& i);
|
||||
void Read(int64& i);
|
||||
void Read(Val128& i);
|
||||
void Read(bool& val);
|
||||
void Read(BeIRTypeEntry*& type);
|
||||
void Read(BeType*& beType);
|
||||
|
|
|
@ -884,6 +884,38 @@ int BeDbgLoc::GetInlineMatchDepth(BeDbgLoc* other)
|
|||
return matchDepth;
|
||||
}
|
||||
|
||||
void BeDbgFunction::HashContent(BeHashContext& hashCtx)
|
||||
{
|
||||
hashCtx.Mixin(TypeId);
|
||||
if (mFile != NULL)
|
||||
mFile->HashReference(hashCtx);
|
||||
hashCtx.Mixin(mLine);
|
||||
hashCtx.MixinStr(mName);
|
||||
hashCtx.MixinStr(mLinkageName);
|
||||
mType->HashReference(hashCtx);
|
||||
for (auto genericArg : mGenericArgs)
|
||||
genericArg->HashReference(hashCtx);
|
||||
for (auto genericConstValueArgs : mGenericArgs)
|
||||
genericConstValueArgs->HashReference(hashCtx);
|
||||
if (mValue != NULL)
|
||||
mValue->HashReference(hashCtx);
|
||||
hashCtx.Mixin(mIsLocalToUnit);
|
||||
hashCtx.Mixin(mIsStaticMethod);
|
||||
hashCtx.Mixin(mFlags);
|
||||
hashCtx.Mixin(mVK);
|
||||
hashCtx.Mixin(mVIndex);
|
||||
hashCtx.Mixin(mVariables.size());
|
||||
for (auto& variable : mVariables)
|
||||
{
|
||||
if (variable == NULL)
|
||||
hashCtx.Mixin(-1);
|
||||
else
|
||||
variable->HashReference(hashCtx);
|
||||
}
|
||||
hashCtx.Mixin(mPrologSize);
|
||||
hashCtx.Mixin(mCodeLen);
|
||||
}
|
||||
|
||||
void BeDbgStructType::SetMembers(SizedArrayImpl<BeMDNode*>& members)
|
||||
{
|
||||
mIsFullyDefined = true;
|
||||
|
|
|
@ -1847,35 +1847,7 @@ public:
|
|||
}*/
|
||||
}
|
||||
|
||||
virtual void HashContent(BeHashContext& hashCtx) override
|
||||
{
|
||||
hashCtx.Mixin(TypeId);
|
||||
hashCtx.Mixin(mLine);
|
||||
hashCtx.MixinStr(mName);
|
||||
hashCtx.MixinStr(mLinkageName);
|
||||
mType->HashReference(hashCtx);
|
||||
for (auto genericArg : mGenericArgs)
|
||||
genericArg->HashReference(hashCtx);
|
||||
for (auto genericConstValueArgs : mGenericArgs)
|
||||
genericConstValueArgs->HashReference(hashCtx);
|
||||
if (mValue != NULL)
|
||||
mValue->HashReference(hashCtx);
|
||||
hashCtx.Mixin(mIsLocalToUnit);
|
||||
hashCtx.Mixin(mIsStaticMethod);
|
||||
hashCtx.Mixin(mFlags);
|
||||
hashCtx.Mixin(mVK);
|
||||
hashCtx.Mixin(mVIndex);
|
||||
hashCtx.Mixin(mVariables.size());
|
||||
for (auto& variable : mVariables)
|
||||
{
|
||||
if (variable == NULL)
|
||||
hashCtx.Mixin(-1);
|
||||
else
|
||||
variable->HashReference(hashCtx);
|
||||
}
|
||||
hashCtx.Mixin(mPrologSize);
|
||||
hashCtx.Mixin(mCodeLen);
|
||||
}
|
||||
virtual void HashContent(BeHashContext& hashCtx) override;
|
||||
};
|
||||
|
||||
class BeDbgInlinedScope : public BeMDNode
|
||||
|
@ -1982,8 +1954,9 @@ public:
|
|||
BE_VALUE_TYPE(BeDbgFile, BeMDNode);
|
||||
|
||||
public:
|
||||
String mFileName;
|
||||
String mFileName;
|
||||
String mDirectory;
|
||||
Val128 mMD5Hash;
|
||||
int mIdx;
|
||||
|
||||
void ToString(String& str);
|
||||
|
@ -1992,6 +1965,7 @@ public:
|
|||
{
|
||||
hashCtx.Mixin(TypeId);
|
||||
hashCtx.MixinStr(mFileName);
|
||||
hashCtx.Mixin(mMD5Hash);
|
||||
hashCtx.MixinStr(mDirectory);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1289,7 +1289,10 @@ void BfDefBuilder::Visit(BfTypeDeclaration* typeDeclaration)
|
|||
SetAndRestoreValue<HashContext*> prevSignatureHashCtx(mSignatureHashCtx, &signatureHashCtx);
|
||||
|
||||
if (bfParser != NULL)
|
||||
{
|
||||
mSignatureHashCtx->MixinStr(bfParser->mFileName);
|
||||
mSignatureHashCtx->Mixin(bfParser->mParserData->mMD5Hash);
|
||||
}
|
||||
HashNode(*mSignatureHashCtx, typeDeclaration->mTypeNode);
|
||||
for (auto& baseClassNode : typeDeclaration->mBaseClasses)
|
||||
HashNode(*mSignatureHashCtx, baseClassNode);
|
||||
|
|
|
@ -1651,6 +1651,12 @@ void BfIRBuilder::Write(int64 intVal)
|
|||
WriteSLEB128(intVal);
|
||||
}
|
||||
|
||||
void BfIRBuilder::Write(Val128 val)
|
||||
{
|
||||
WriteSLEB128((int64)val.mLow);
|
||||
WriteSLEB128((int64)val.mHigh);
|
||||
}
|
||||
|
||||
void BfIRBuilder::Write(const StringImpl&str)
|
||||
{
|
||||
WriteSLEB128((int)str.length());
|
||||
|
@ -4718,9 +4724,9 @@ BfIRMDNode BfIRBuilder::DbgCreateCompileUnit(int lang, const StringImpl& fileNam
|
|||
return retVal;
|
||||
}
|
||||
|
||||
BfIRMDNode BfIRBuilder::DbgCreateFile(const StringImpl& fileName, const StringImpl& directory)
|
||||
BfIRMDNode BfIRBuilder::DbgCreateFile(const StringImpl& fileName, const StringImpl& directory, const Val128& md5Hash)
|
||||
{
|
||||
BfIRMDNode retVal = WriteCmd(BfIRCmd_DbgCreateFile, fileName, directory);
|
||||
BfIRMDNode retVal = WriteCmd(BfIRCmd_DbgCreateFile, fileName, directory, md5Hash);
|
||||
NEW_CMD_INSERTED_IRMD;
|
||||
|
||||
if (mDbgVerifyCodeGen && gDebugDbgLoc)
|
||||
|
|
|
@ -58,6 +58,7 @@ class BfFieldInstance;
|
|||
class BfFileInstance;
|
||||
class BfParser;
|
||||
class BfParserData;
|
||||
class Val128;
|
||||
|
||||
class BfFilePosition
|
||||
{
|
||||
|
@ -905,6 +906,7 @@ public:
|
|||
void Write(bool val);
|
||||
void Write(int val);
|
||||
void Write(int64 val);
|
||||
void Write(Val128 val);
|
||||
void Write(const StringImpl& str);
|
||||
void Write(const BfIRValue& irValue);
|
||||
void Write(BfTypeCode typeCode);
|
||||
|
@ -1195,7 +1197,7 @@ public:
|
|||
void DbgAddPrefix(String& name);
|
||||
BfIRMDNode DbgCreateCompileUnit(int lang, const StringImpl& filename, const StringImpl& directory, const StringImpl& producer, bool isOptimized,
|
||||
const StringImpl& flags, int runtimeVer, bool linesOnly);
|
||||
BfIRMDNode DbgCreateFile(const StringImpl& fileName, const StringImpl& directory);
|
||||
BfIRMDNode DbgCreateFile(const StringImpl& fileName, const StringImpl& directory, const Val128& md5Hash);
|
||||
BfIRMDNode DbgGetCurrentLocation();
|
||||
void DbgSetType(BfType * type, BfIRMDNode diType);
|
||||
void DbgSetInstType(BfType * type, BfIRMDNode diType);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "BfIRCodeGen.h"
|
||||
#include "BfModule.h"
|
||||
#include "BeefySysLib/util/BeefPerf.h"
|
||||
#include "BeefySysLib/util/Hash.h"
|
||||
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable:4141)
|
||||
|
@ -113,6 +114,7 @@
|
|||
USING_NS_BF;
|
||||
|
||||
#pragma warning(disable:4146)
|
||||
#pragma warning(disable:4996)
|
||||
|
||||
struct BuiltinEntry
|
||||
{
|
||||
|
@ -477,6 +479,12 @@ void BfIRCodeGen::Read(int64& i)
|
|||
i = ReadSLEB128();
|
||||
}
|
||||
|
||||
void BfIRCodeGen::Read(Val128& i)
|
||||
{
|
||||
i.mLow = (uint64)ReadSLEB128();
|
||||
i.mHigh = (uint64)ReadSLEB128();
|
||||
}
|
||||
|
||||
void BfIRCodeGen::Read(bool& val)
|
||||
{
|
||||
val = mStream->Read() != 0;
|
||||
|
@ -2741,7 +2749,14 @@ void BfIRCodeGen::HandleNextCmd()
|
|||
{
|
||||
CMD_PARAM(String, fileName);
|
||||
CMD_PARAM(String, directory);
|
||||
SetResult(curId, mDIBuilder->createFile(fileName.c_str(), directory.c_str()));
|
||||
CMD_PARAM(Val128, md5Hash);
|
||||
|
||||
char hashStr[64];
|
||||
for (int i = 0; i < 16; i++)
|
||||
sprintf(&hashStr[i * 2], "%.2x", ((uint8*)&md5Hash)[i]);
|
||||
|
||||
SetResult(curId, mDIBuilder->createFile(fileName.c_str(), directory.c_str(),
|
||||
llvm::DIFile::ChecksumInfo<llvm::StringRef>(llvm::DIFile::CSK_MD5, hashStr)));
|
||||
}
|
||||
break;
|
||||
case BfIRCmd_ConstValueI64:
|
||||
|
|
|
@ -111,6 +111,7 @@ public:
|
|||
void Read(StringImpl& str);
|
||||
void Read(int& i);
|
||||
void Read(int64& i);
|
||||
void Read(Val128& i);
|
||||
void Read(bool& val);
|
||||
void Read(BfIRTypeEntry*& type);
|
||||
void Read(llvm::Type*& llvmType);
|
||||
|
|
|
@ -2168,7 +2168,7 @@ BfFileInstance* BfModule::GetFileFromNode(BfAstNode* astNode)
|
|||
fileName[i] = DIR_SEP_CHAR;
|
||||
}
|
||||
|
||||
bfFileInstance->mDIFile = mBfIRBuilder->DbgCreateFile(fileName.Substring(slashPos + 1), fileName.Substring(0, slashPos));
|
||||
bfFileInstance->mDIFile = mBfIRBuilder->DbgCreateFile(fileName.Substring(slashPos + 1), fileName.Substring(0, slashPos), bfParser->mMD5Hash);
|
||||
}
|
||||
return bfFileInstance;
|
||||
}
|
||||
|
|
|
@ -3382,6 +3382,12 @@ BF_EXPORT void BF_CALLTYPE BfParser_SetCharIdData(BfParser* bfParser, uint8* dat
|
|||
memcpy(bfParser->mParserData->mCharIdData, data, length);
|
||||
}
|
||||
|
||||
BF_EXPORT void BF_CALLTYPE BfParser_SetHashMD5(BfParser* bfParser, Val128* md5Hash)
|
||||
{
|
||||
if (md5Hash != NULL)
|
||||
bfParser->mParserData->mMD5Hash = *md5Hash;
|
||||
}
|
||||
|
||||
BF_EXPORT void BF_CALLTYPE BfParser_Delete(BfParser* bfParser)
|
||||
{
|
||||
if (bfParser->mNextRevision != NULL)
|
||||
|
|
|
@ -68,6 +68,7 @@ public:
|
|||
BfParser* mUniqueParser; // For non-cached usage (ie: autocomplete)
|
||||
String mFileName;
|
||||
uint8* mCharIdData;
|
||||
Val128 mMD5Hash;
|
||||
|
||||
HashSet<String> mDefines_Def;
|
||||
HashSet<String> mDefines_NoDef;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue