Index: lldb/trunk/lit/Modules/PECOFF/sections-names.yaml =================================================================== --- lldb/trunk/lit/Modules/PECOFF/sections-names.yaml +++ lldb/trunk/lit/Modules/PECOFF/sections-names.yaml @@ -0,0 +1,52 @@ +# RUN: yaml2obj %s > %t +# RUN: lldb-test object-file %t | FileCheck %s + +# CHECK: Name: .text{{$}} +# CHECK: Name: 1234567{{$}} +# CHECK: Name: 12345678{{$}} +# CHECK: Name: 123456789{{$}} + +--- !COFF +OptionalHeader: + AddressOfEntryPoint: 4616 + ImageBase: 1073741824 + SectionAlignment: 4096 + FileAlignment: 512 + MajorOperatingSystemVersion: 6 + MinorOperatingSystemVersion: 0 + MajorImageVersion: 0 + MinorImageVersion: 0 + MajorSubsystemVersion: 6 + MinorSubsystemVersion: 0 + Subsystem: IMAGE_SUBSYSTEM_WINDOWS_CUI + DLLCharacteristics: [ IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA, IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE, IMAGE_DLL_CHARACTERISTICS_NX_COMPAT, IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE ] + SizeOfStackReserve: 1048576 + SizeOfStackCommit: 4096 + SizeOfHeapReserve: 1048576 + SizeOfHeapCommit: 4096 +header: + Machine: IMAGE_FILE_MACHINE_AMD64 + Characteristics: [ IMAGE_FILE_EXECUTABLE_IMAGE, IMAGE_FILE_LARGE_ADDRESS_AWARE ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + VirtualAddress: 4096 + VirtualSize: 64 # '@', if it makes its way into the name field + SectionData: DEADBEEFBAADF00D + - Name: 1234567 + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ] + VirtualAddress: 442368 + VirtualSize: 64 + SectionData: DEADBEEFBAADF00D + - Name: 12345678 + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ] + VirtualAddress: 446464 + VirtualSize: 64 + SectionData: DEADBEEFBAADF00D + - Name: 123456789 + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ] + VirtualAddress: 450560 + VirtualSize: 64 + SectionData: DEADBEEFBAADF00D +symbols: [] +... Index: lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h =================================================================== --- lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h +++ lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h @@ -270,7 +270,7 @@ void DumpSectionHeader(lldb_private::Stream *s, const section_header_t &sh); void DumpDependentModules(lldb_private::Stream *s); - bool GetSectionName(std::string §_name, const section_header_t §); + llvm::StringRef GetSectionName(const section_header_t §); typedef std::vector SectionHeaderColl; typedef SectionHeaderColl::iterator SectionHeaderCollIter; Index: lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp =================================================================== --- lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp +++ lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp @@ -530,22 +530,20 @@ return !m_sect_headers.empty(); } -bool ObjectFilePECOFF::GetSectionName(std::string §_name, - const section_header_t §) { - if (sect.name[0] == '/') { - lldb::offset_t stroff = strtoul(§.name[1], NULL, 10); +llvm::StringRef ObjectFilePECOFF::GetSectionName(const section_header_t §) { + llvm::StringRef hdr_name(sect.name, llvm::array_lengthof(sect.name)); + hdr_name = hdr_name.split('\0').first; + if (hdr_name.consume_front("/")) { + lldb::offset_t stroff; + if (!to_integer(hdr_name, stroff, 10)) + return ""; lldb::offset_t string_file_offset = m_coff_header.symoff + (m_coff_header.nsyms * 18) + stroff; - const char *name = m_data.GetCStr(&string_file_offset); - if (name) { - sect_name = name; - return true; - } - - return false; + if (const char *name = m_data.GetCStr(&string_file_offset)) + return name; + return ""; } - sect_name = sect.name; - return true; + return hdr_name; } //---------------------------------------------------------------------- @@ -712,9 +710,7 @@ const uint32_t nsects = m_sect_headers.size(); ModuleSP module_sp(GetModule()); for (uint32_t idx = 0; idx < nsects; ++idx) { - std::string sect_name; - GetSectionName(sect_name, m_sect_headers[idx]); - ConstString const_sect_name(sect_name.c_str()); + ConstString const_sect_name(GetSectionName(m_sect_headers[idx])); static ConstString g_code_sect_name(".code"); static ConstString g_CODE_sect_name("CODE"); static ConstString g_data_sect_name(".data"); @@ -1086,8 +1082,7 @@ //---------------------------------------------------------------------- void ObjectFilePECOFF::DumpSectionHeader(Stream *s, const section_header_t &sh) { - std::string name; - GetSectionName(name, sh); + std::string name = GetSectionName(sh); s->Printf("%-16s 0x%8.8x 0x%8.8x 0x%8.8x 0x%8.8x 0x%8.8x 0x%8.8x 0x%4.4x " "0x%4.4x 0x%8.8x\n", name.c_str(), sh.vmaddr, sh.vmsize, sh.offset, sh.size, sh.reloff,