Skip to content

Commit 0870afc

Browse files
alvinhochunmstorsjo
authored andcommitted
[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
1 parent bf0cda9 commit 0870afc

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,10 @@ void ObjectFilePECOFF::AppendFromExportTable(SectionList *sect_list,
826826
// Note: symbol name may be empty if it is only exported by ordinal.
827827
symbol.GetMangled().SetValue(ConstString(sym_name));
828828

829+
uint32_t ordinal;
830+
llvm::cantFail(entry.getOrdinal(ordinal));
831+
symbol.SetID(ordinal);
832+
829833
uint32_t function_rva;
830834
if (auto err = entry.getExportRVA(function_rva)) {
831835
LLDB_LOG(log,
@@ -834,10 +838,19 @@ void ObjectFilePECOFF::AppendFromExportTable(SectionList *sect_list,
834838
sym_name, llvm::fmt_consume(std::move(err)));
835839
continue;
836840
}
841+
// Skip the symbol if it doesn't look valid.
842+
if (function_rva == 0 && sym_name.empty())
843+
continue;
837844
symbol.GetAddressRef() =
838845
Address(m_coff_header_opt.image_base + function_rva, sect_list);
839-
symbol.SetType(lldb::eSymbolTypeCode);
840-
symbol.SetDebug(true);
846+
847+
// An exported symbol may be either code or data. Guess by checking whether
848+
// the section containing the symbol is executable.
849+
symbol.SetType(lldb::eSymbolTypeData);
850+
if (auto section_sp = symbol.GetAddressRef().GetSection())
851+
if (section_sp->GetPermissions() & ePermissionsExecutable)
852+
symbol.SetType(lldb::eSymbolTypeCode);
853+
symbol.SetExternal(true);
841854
symtab.AddSymbol(symbol);
842855
}
843856
}

lldb/test/Shell/ObjectFile/PECOFF/symbols-export-table.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
# CHECK: UserID DSX Type File Address/Value {{.*}} Size Flags Name
88
# CHECK-NEXT: ------
9-
# CHECK-NEXT: 4294967295 D Code 0x0000000180001020 0x{{[0-9a-f]+}} 0x{{[0-9a-f]+}} exportFnAlias
10-
# CHECK-NEXT: 4294967295 D Code 0x0000000180001010 0x{{[0-9a-f]+}} 0x{{[0-9a-f]+}} exportFunc
11-
# CHECK-NEXT: 4294967295 D Code 0x0000000180003000 0x{{[0-9a-f]+}} 0x{{[0-9a-f]+}} exportInt
12-
# CHECK-NEXT: 4294967295 D Code 0x0000000180003004 0x{{[0-9a-f]+}} 0x{{[0-9a-f]+}} exportIntAlias
9+
# CHECK-NEXT: 1 X Code 0x0000000180001020 0x{{[0-9a-f]+}} 0x{{[0-9a-f]+}} exportFnAlias
10+
# CHECK-NEXT: 2 X Code 0x0000000180001010 0x{{[0-9a-f]+}} 0x{{[0-9a-f]+}} exportFunc
11+
# CHECK-NEXT: 3 X Data 0x0000000180003000 0x{{[0-9a-f]+}} 0x{{[0-9a-f]+}} exportInt
12+
# CHECK-NEXT: 4 X Data 0x0000000180003004 0x{{[0-9a-f]+}} 0x{{[0-9a-f]+}} exportIntAlias
1313
# CHECK-NEXT: 4294967295 Code 0x0000000180001000 0x{{[0-9a-f]+}} 0x{{[0-9a-f]+}} entry
1414
# CHECK-NEXT: 4294967295 Code 0x0000000180001010 0x{{[0-9a-f]+}} 0x{{[0-9a-f]+}} exportFunc
1515
# CHECK-NEXT: 4294967295 Code 0x0000000180001020 0x{{[0-9a-f]+}} 0x{{[0-9a-f]+}} aliasFunc

0 commit comments

Comments
 (0)