From 0870afc68e1a1ec303af1d0dbf952dd2c41f478a Mon Sep 17 00:00:00 2001 From: Alvin Wong Date: Wed, 28 Sep 2022 12:43:14 +0300 Subject: [PATCH] [lldb][COFF] Improve info of symbols from export table - Skip dummy/invalid export symbols. - Make the export ordinal of export symbols visible when dumping the symtab. - Stop setting the 'Debug' flag and set the 'External' flag instead to better match the meaning of export symbols. - Try to guess the type (code vs data) of the symbol from section flags. Reviewed By: labath Differential Revision: https://reviews.llvm.org/D134265 --- .../Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp | 17 +++++++++++++++-- .../Shell/ObjectFile/PECOFF/symbols-export-table.yaml | 8 ++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp b/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp index 3890e8b..6139381 100644 --- a/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp +++ b/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp @@ -826,6 +826,10 @@ void ObjectFilePECOFF::AppendFromExportTable(SectionList *sect_list, // Note: symbol name may be empty if it is only exported by ordinal. symbol.GetMangled().SetValue(ConstString(sym_name)); + uint32_t ordinal; + llvm::cantFail(entry.getOrdinal(ordinal)); + symbol.SetID(ordinal); + uint32_t function_rva; if (auto err = entry.getExportRVA(function_rva)) { LLDB_LOG(log, @@ -834,10 +838,19 @@ void ObjectFilePECOFF::AppendFromExportTable(SectionList *sect_list, sym_name, llvm::fmt_consume(std::move(err))); continue; } + // Skip the symbol if it doesn't look valid. + if (function_rva == 0 && sym_name.empty()) + continue; symbol.GetAddressRef() = Address(m_coff_header_opt.image_base + function_rva, sect_list); - symbol.SetType(lldb::eSymbolTypeCode); - symbol.SetDebug(true); + + // An exported symbol may be either code or data. Guess by checking whether + // the section containing the symbol is executable. + symbol.SetType(lldb::eSymbolTypeData); + if (auto section_sp = symbol.GetAddressRef().GetSection()) + if (section_sp->GetPermissions() & ePermissionsExecutable) + symbol.SetType(lldb::eSymbolTypeCode); + symbol.SetExternal(true); symtab.AddSymbol(symbol); } } diff --git a/lldb/test/Shell/ObjectFile/PECOFF/symbols-export-table.yaml b/lldb/test/Shell/ObjectFile/PECOFF/symbols-export-table.yaml index e0298fd..f136db38 100644 --- a/lldb/test/Shell/ObjectFile/PECOFF/symbols-export-table.yaml +++ b/lldb/test/Shell/ObjectFile/PECOFF/symbols-export-table.yaml @@ -6,10 +6,10 @@ # CHECK: UserID DSX Type File Address/Value {{.*}} Size Flags Name # CHECK-NEXT: ------ -# CHECK-NEXT: 4294967295 D Code 0x0000000180001020 0x{{[0-9a-f]+}} 0x{{[0-9a-f]+}} exportFnAlias -# CHECK-NEXT: 4294967295 D Code 0x0000000180001010 0x{{[0-9a-f]+}} 0x{{[0-9a-f]+}} exportFunc -# CHECK-NEXT: 4294967295 D Code 0x0000000180003000 0x{{[0-9a-f]+}} 0x{{[0-9a-f]+}} exportInt -# CHECK-NEXT: 4294967295 D Code 0x0000000180003004 0x{{[0-9a-f]+}} 0x{{[0-9a-f]+}} exportIntAlias +# CHECK-NEXT: 1 X Code 0x0000000180001020 0x{{[0-9a-f]+}} 0x{{[0-9a-f]+}} exportFnAlias +# CHECK-NEXT: 2 X Code 0x0000000180001010 0x{{[0-9a-f]+}} 0x{{[0-9a-f]+}} exportFunc +# CHECK-NEXT: 3 X Data 0x0000000180003000 0x{{[0-9a-f]+}} 0x{{[0-9a-f]+}} exportInt +# CHECK-NEXT: 4 X Data 0x0000000180003004 0x{{[0-9a-f]+}} 0x{{[0-9a-f]+}} exportIntAlias # CHECK-NEXT: 4294967295 Code 0x0000000180001000 0x{{[0-9a-f]+}} 0x{{[0-9a-f]+}} entry # CHECK-NEXT: 4294967295 Code 0x0000000180001010 0x{{[0-9a-f]+}} 0x{{[0-9a-f]+}} exportFunc # CHECK-NEXT: 4294967295 Code 0x0000000180001020 0x{{[0-9a-f]+}} 0x{{[0-9a-f]+}} aliasFunc -- 2.7.4