================
@@ -394,6 +394,103 @@ bool ProcessGDBRemote::ParsePythonTargetDefinition(
return false;
}
+static bool ParseMemoryRegionInfoJSON(StructuredData::Object *json,
+ MemoryRegionInfo &ri,
+ uint32_t page_size) {
+ ri.Clear();
+ if (!json || !json->GetAsArray())
+ return false;
+ bool returnval = true;
+ json->GetAsArray()->ForEach(
+ [&ri, page_size, &returnval](StructuredData::Object *obj) -> bool {
+ StructuredData::Dictionary *dict = obj->GetAsDictionary();
+ if (!dict)
+ returnval = false;
+
+ if (!dict->HasKey("start") || !dict->HasKey("size") ||
+ !dict->HasKey("permissions"))
+ returnval = false;
+
+ ri.GetRange().SetRangeBase(
+ dict->GetValueForKey("start")->GetUnsignedIntegerValue());
+ ri.GetRange().SetByteSize(
+ dict->GetValueForKey("size")->GetUnsignedIntegerValue());
+ llvm::StringRef permissions =
+ dict->GetValueForKey("permissions")->GetStringValue();
+ if (permissions.contains('r'))
+ ri.SetReadable(eLazyBoolYes);
+ else
+ ri.SetReadable(eLazyBoolNo);
+
+ if (permissions.contains('w'))
+ ri.SetWritable(eLazyBoolYes);
+ else
+ ri.SetWritable(eLazyBoolNo);
+
+ if (permissions.contains('x'))
+ ri.SetExecutable(eLazyBoolYes);
+ else
+ ri.SetExecutable(eLazyBoolNo);
+
+ if (!permissions.empty())
+ ri.SetMapped(eLazyBoolYes);
+ else
+ ri.SetMapped(eLazyBoolNo);
+
+ if (dict->HasKey("flags")) {
+ dict->GetValueForKey("flags")->GetAsArray()->ForEach(
+ [&ri](StructuredData::Object *obj) -> bool {
+ if (!obj->GetAsString())
+ return true;
+ if (obj->GetAsString()->GetValue() == "mt")
+ ri.SetMemoryTagged(eLazyBoolYes);
+ if (obj->GetAsString()->GetValue() == "ss")
+ ri.SetIsShadowStack(eLazyBoolYes);
+ return true;
+ });
+ }
+
+ if (dict->HasKey("name") &&
dict->GetValueForKey("name")->GetAsString())
+ ri.SetName(dict->GetValueForKey("name")
+ ->GetAsString()
+ ->GetValue()
+ .str()
+ .c_str());
+
+ if (dict->HasKey("dirty_pages") &&
+ dict->GetValueForKey("dirty_pages")->GetAsArray()) {
+ std::vector<addr_t> dirty_pages;
+ dict->GetValueForKey("dirty_pages")
+ ->GetAsArray()
+ ->ForEach([&dirty_pages](StructuredData::Object *obj) -> bool {
+ if (!obj->GetAsUnsignedInteger())
+ return true;
+ dirty_pages.push_back(
+ obj->GetAsUnsignedInteger()->GetUnsignedIntegerValue());
+ return true;
+ });
+ }
+
+ if (dict->HasKey("types")) {
+ dict->GetValueForKey("types")->GetAsArray()->ForEach(
+ [&ri](StructuredData::Object *obj) -> bool {
+ if (!obj->GetAsString())
+ return true;
+ if (obj->GetAsString()->GetValue() == "stack")
+ ri.SetIsStackMemory(eLazyBoolYes);
+ return true;
+ });
+ }
+
+ if (page_size != 0)
+ ri.SetPageSize(page_size);
+
+ return true;
+ });
+
+ return true;
----------------
jasonmolenda wrote:
`returnval` here is what `ParseMemoryRegionInfoJSON()` returns to its caller
Most of this method is in a lambda that is run over the JSON array objects, it
captures that value. It sets `returnval` to false if are missing a required
field, so `ParseMemoryRegionInfoJSON()` returns false.
The other `return true`'s here are in other `ForEach` lambdas, and indicate
that we should continue to process elements.
https://github.com/llvm/llvm-project/pull/202509
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits