summaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/ObjectFile/JSON/ObjectFileJSON.cpp
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@fb.com>2025-03-04 16:19:20 -0800
committerGitHub <noreply@github.com>2025-03-04 16:19:20 -0800
commit27901cec0e76d2cbf648b3b63d5b2fec1d46bb9c (patch)
treefac7bbf5ca4c6cce688053a7643e3f62181ee06c /lldb/source/Plugins/ObjectFile/JSON/ObjectFileJSON.cpp
parente697c99b63224069daa3814f536a69fecab8cd4e (diff)
Add subsection and permissions support to ObjectFileJSON. (#129801)
This patch adds the ability to create subsections in a section and allows permissions to be specified.
Diffstat (limited to 'lldb/source/Plugins/ObjectFile/JSON/ObjectFileJSON.cpp')
-rw-r--r--lldb/source/Plugins/ObjectFile/JSON/ObjectFileJSON.cpp61
1 files changed, 49 insertions, 12 deletions
diff --git a/lldb/source/Plugins/ObjectFile/JSON/ObjectFileJSON.cpp b/lldb/source/Plugins/ObjectFile/JSON/ObjectFileJSON.cpp
index 8e90fac46f34..0f9676b836b5 100644
--- a/lldb/source/Plugins/ObjectFile/JSON/ObjectFileJSON.cpp
+++ b/lldb/source/Plugins/ObjectFile/JSON/ObjectFileJSON.cpp
@@ -180,18 +180,55 @@ void ObjectFileJSON::CreateSections(SectionList &unified_section_list) {
m_sections_up = std::make_unique<SectionList>();
lldb::user_id_t id = 1;
- for (const auto &section : m_sections) {
- auto section_sp = std::make_shared<Section>(
- GetModule(), this,
- /*sect_id=*/id++,
- /*name=*/ConstString(section.name),
- /*sect_type=*/section.type.value_or(eSectionTypeCode),
- /*file_vm_addr=*/section.address.value_or(0),
- /*vm_size=*/section.size.value_or(0),
- /*file_offset=*/0,
- /*file_size=*/0,
- /*log2align=*/0,
- /*flags=*/0);
+ for (const auto &json_section : m_sections) {
+ auto make_section = [this, &id](const JSONSection &section,
+ SectionSP parent_section_sp =
+ nullptr) -> SectionSP {
+ SectionSP section_sp;
+ if (parent_section_sp) {
+ section_sp = std::make_shared<Section>(
+ parent_section_sp, GetModule(), this,
+ /*sect_id=*/id++,
+ /*name=*/ConstString(section.name),
+ /*sect_type=*/section.type.value_or(eSectionTypeCode),
+ /*file_vm_addr=*/section.address.value_or(0) -
+ parent_section_sp->GetFileAddress(),
+ /*vm_size=*/section.size.value_or(0),
+ /*file_offset=*/0,
+ /*file_size=*/0,
+ /*log2align=*/0,
+ /*flags=*/0);
+
+ } else {
+ section_sp = std::make_shared<Section>(
+ GetModule(), this,
+ /*sect_id=*/id++,
+ /*name=*/ConstString(section.name),
+ /*sect_type=*/section.type.value_or(eSectionTypeCode),
+ /*file_vm_addr=*/section.address.value_or(0),
+ /*vm_size=*/section.size.value_or(0),
+ /*file_offset=*/0,
+ /*file_size=*/0,
+ /*log2align=*/0,
+ /*flags=*/0);
+ }
+ uint32_t permissions = 0;
+ if (section.read.value_or(0))
+ permissions |= lldb::ePermissionsReadable;
+ if (section.write.value_or(0))
+ permissions |= lldb::ePermissionsWritable;
+ if (section.execute.value_or(0))
+ permissions |= lldb::ePermissionsExecutable;
+ if (permissions)
+ section_sp->SetPermissions(permissions);
+ return section_sp;
+ };
+ auto section_sp = make_section(json_section);
+ for (const auto &subsection : json_section.subsections) {
+ SectionSP subsection_sp = make_section(subsection, section_sp);
+ section_sp->GetChildren().AddSection(subsection_sp);
+ }
+
m_sections_up->AddSection(section_sp);
unified_section_list.AddSection(section_sp);
}