Skip to content

Commit

Permalink
[SharedCache] Serialize SharedCache::m_symbolInfos
Browse files Browse the repository at this point in the history
`SharedCache::m_symbolInfos` isn't being serialized but there is an attempt to deserialize it. This commit adds in the code to serialize it.

I slightly modified the format because I didn't really understand how it was expected to be serialized based on the deserialization code. The deserialization code looked wrong to me but its likely a misunderstanding on my part. I kept it similar to how `m_exportInfos` is serialized.
WeiN76LQh authored and WeiN76LQh committed Nov 21, 2024
1 parent 7f1a310 commit f990bc8
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions view/sharedcache/core/SharedCache.h
Original file line number Diff line number Diff line change
@@ -976,6 +976,27 @@ namespace SharedCacheCore {
}
m_activeContext.doc.AddMember("exportInfos", exportInfos, m_activeContext.allocator);

rapidjson::Document symbolInfos(rapidjson::kArrayType);
for (const auto& pair1 : m_symbolInfos)
{
rapidjson::Value subObj(rapidjson::kObjectType);
rapidjson::Value subArr(rapidjson::kArrayType);
for (const auto& pair2 : pair1.second)
{
rapidjson::Value subSubArr(rapidjson::kArrayType);
subSubArr.PushBack(pair2.first, m_activeContext.allocator);
subSubArr.PushBack(pair2.second.first, m_activeContext.allocator);
subSubArr.PushBack(pair2.second.second, m_activeContext.allocator);
subArr.PushBack(subSubArr, m_activeContext.allocator);
}

subObj.AddMember("key", pair1.first, m_activeContext.allocator);
subObj.AddMember("value", subArr, m_activeContext.allocator);

symbolInfos.PushBack(subObj, m_activeContext.allocator);
}
m_activeContext.doc.AddMember("symbolInfos", symbolInfos, m_activeContext.allocator);

rapidjson::Value backingCaches(rapidjson::kArrayType);
for (auto bc : m_backingCaches)
{
@@ -1055,12 +1076,12 @@ namespace SharedCacheCore {
for (auto& symbolInfo : m_activeDeserContext.doc["symbolInfos"].GetArray())
{
std::vector<std::pair<uint64_t, std::pair<BNSymbolType, std::string>>> symbolInfoVec;
for (auto& symbolInfoPair : symbolInfo.GetArray())
for (auto& symbolInfoPair : symbolInfo["value"].GetArray())
{
symbolInfoVec.push_back({symbolInfoPair[0].GetUint64(),
{(BNSymbolType)symbolInfoPair[1].GetUint(), symbolInfoPair[2].GetString()}});
}
m_symbolInfos[symbolInfo[0].GetUint64()] = symbolInfoVec;
m_symbolInfos[symbolInfo["key"].GetUint64()] = symbolInfoVec;
}
m_backingCaches.clear();
for (auto& bcV : m_activeDeserContext.doc["backingCaches"].GetArray())

0 comments on commit f990bc8

Please sign in to comment.