diff --git a/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp b/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp --- a/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp +++ b/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp @@ -826,6 +826,10 @@ // 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 @@ 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 --- 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