https://github.com/bulbazord created https://github.com/llvm/llvm-project/pull/218490
I plan on replacing the string type in LLDB's Section class, so the first thing I will do is remove ConstString from all producers. >From 856278f72c6a68a46d0d64a8ebdb7fb9325e0cf1 Mon Sep 17 00:00:00 2001 From: Alex Langford <[email protected]> Date: Mon, 24 Aug 2026 11:41:14 -0700 Subject: [PATCH] [lldb] Replace string type in ELFSectionHeaderInfo I plan on replacing the string type in LLDB's Section class, so the first thing I will do is remove ConstString from all producers. --- .../Plugins/ObjectFile/ELF/ObjectFileELF.cpp | 25 +++++++++---------- .../Plugins/ObjectFile/ELF/ObjectFileELF.h | 4 +-- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp index 12739c17c0b65..9fc813168466e 100644 --- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp +++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp @@ -1736,9 +1736,8 @@ size_t ObjectFileELF::GetSectionHeaderInfo(SectionHeaderColl §ion_headers, const ELFSectionHeaderInfo &sheader = *I; const uint64_t section_size = sheader.sh_type == SHT_NOBITS ? 0 : sheader.sh_size; - ConstString name(shstr_data.PeekCStr(I->sh_name)); - - I->section_name = name; + llvm::StringRef name(shstr_data.PeekCStr(I->sh_name)); + I->section_name = name.str(); if (arch_spec.IsMIPS()) { uint32_t arch_flags = arch_spec.GetFlags(); @@ -1896,11 +1895,11 @@ ObjectFileELF::GetSectionHeaderByIndex(lldb::user_id_t id) { return nullptr; } -lldb::user_id_t ObjectFileELF::GetSectionIndexByName(const char *name) { - if (!name || !name[0] || !ParseSectionHeaders()) +lldb::user_id_t ObjectFileELF::GetSectionIndexByName(llvm::StringRef name) { + if (name.empty() || !ParseSectionHeaders()) return 0; for (size_t i = 1; i < m_section_headers.size(); ++i) - if (m_section_headers[i].section_name == ConstString(name)) + if (m_section_headers[i].section_name == name) return i; return 0; } @@ -1944,7 +1943,7 @@ SectionType ObjectFileELF::GetSectionType(const ELFSectionHeaderInfo &H) const { case SHT_DYNAMIC: return eSectionTypeELFDynamicLinkInfo; } - return GetSectionTypeFromName(H.section_name.GetStringRef()); + return GetSectionTypeFromName(H.section_name); } static Permissions GetPermissions(const ELFSectionHeader &H) { @@ -2150,7 +2149,7 @@ void ObjectFileELF::CreateSections(SectionList &unified_section_list) { I != m_section_headers.end(); ++I) { const ELFSectionHeaderInfo &header = *I; - ConstString &name = I->section_name; + const std::string &name = I->section_name; const uint64_t file_size = header.sh_type == SHT_NOBITS ? 0 : header.sh_size; @@ -2170,8 +2169,8 @@ void ObjectFileELF::CreateSections(SectionList &unified_section_list) { this, // ObjectFile to which this section belongs and should // read section data from. SectionIndex(I), // Section ID. - name, // Section name. - sect_type, // Section type. + ConstString(name), // Section name. + sect_type, // Section type. InfoOr->Range.GetRangeBase(), // VM address. InfoOr->Range.GetByteSize(), // VM size in bytes of this section. header.sh_offset, // Offset of this section in the file. @@ -3397,7 +3396,7 @@ void ObjectFileELF::RelocateSection(lldb_private::Section *section) for (SectionHeaderCollIter I = m_section_headers.begin(); I != m_section_headers.end(); ++I) { if (I->sh_type == SHT_RELA || I->sh_type == SHT_REL) { - llvm::StringRef hay_name = I->section_name.GetStringRef(); + llvm::StringRef hay_name(I->section_name); if (hay_name.empty()) continue; if (needle == hay_name || needlea == hay_name) { @@ -3744,8 +3743,8 @@ void ObjectFileELF::DumpELFSectionHeaders(Stream *s) { I != m_section_headers.end(); ++I, ++idx) { s->Printf("[%2u] ", idx); ObjectFileELF::DumpELFSectionHeader(s, *I); - const char *section_name = I->section_name.AsCString(""); - if (section_name) + const std::string §ion_name = I->section_name; + if (!section_name.empty()) *s << ' ' << section_name << "\n"; } } diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h index aa94e625f64e1..e37c8cf07c334 100644 --- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h +++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h @@ -176,7 +176,7 @@ class ObjectFileELF : public lldb_private::ObjectFile { typedef std::vector<elf::ELFProgramHeader> ProgramHeaderColl; struct ELFSectionHeaderInfo : public elf::ELFSectionHeader { - lldb_private::ConstString section_name; + std::string section_name; }; typedef std::vector<ELFSectionHeaderInfo> SectionHeaderColl; @@ -348,7 +348,7 @@ class ObjectFileELF : public lldb_private::ObjectFile { /// index of the corresponding section or zero if no section with the given /// name can be found (note that section indices are always 1 based, and so /// section index 0 is never valid). - lldb::user_id_t GetSectionIndexByName(const char *name); + lldb::user_id_t GetSectionIndexByName(llvm::StringRef name); /// Returns the section header with the given id or NULL. const ELFSectionHeaderInfo *GetSectionHeaderByIndex(lldb::user_id_t id); _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
