[Lldb-commits] [lldb] 0870afc - [lldb][COFF] Improve info of symbols from export table

Martin Storsjö via lldb-commits lldb-commits at lists.llvm.org
Wed Sep 28 02:58:18 PDT 2022


Author: Alvin Wong
Date: 2022-09-28T12:57:10+03:00
New Revision: 0870afc68e1a1ec303af1d0dbf952dd2c41f478a

URL: https://github.com/llvm/llvm-project/commit/0870afc68e1a1ec303af1d0dbf952dd2c41f478a
DIFF: https://github.com/llvm/llvm-project/commit/0870afc68e1a1ec303af1d0dbf952dd2c41f478a.diff

LOG: [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

Added: 
    

Modified: 
    lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
    lldb/test/Shell/ObjectFile/PECOFF/symbols-export-table.yaml

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp b/lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
index 3890e8b997fdc..613938161df5d 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 e0298fdf797cf..f136db38f2a1d 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


        


More information about the lldb-commits mailing list