[Lldb-commits] [PATCH] D134265: [lldb][COFF] Improve info of symbols from export table

Alvin Wong via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Sep 20 01:54:09 PDT 2022


alvinhochun created this revision.
alvinhochun added reviewers: labath, DavidSpickett, mstorsjo.
Herald added a project: All.
alvinhochun requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

- 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.

Depends on D134196 <https://reviews.llvm.org/D134196>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134265

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


Index: lldb/test/Shell/ObjectFile/PECOFF/symbols-export-table.yaml
===================================================================
--- lldb/test/Shell/ObjectFile/PECOFF/symbols-export-table.yaml
+++ lldb/test/Shell/ObjectFile/PECOFF/symbols-export-table.yaml
@@ -6,8 +6,8 @@
 
 # CHECK:          UserID DSX Type    File Address/Value {{.*}} Size            Flags           Name
 # CHECK-NEXT:     ------
-# 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:          1   X Code    0x0000000180001010        0x{{[0-9a-f]+}} 0x{{[0-9a-f]+}} exportFunc
+# CHECK-NEXT:          2   X Data    0x0000000180003000        0x{{[0-9a-f]+}} 0x{{[0-9a-f]+}} exportInt
 # 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     Invalid 0x0000000180003000        0x{{[0-9a-f]+}} 0x{{[0-9a-f]+}} exportInt
Index: lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
===================================================================
--- lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
+++ 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);
   }
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134265.461508.patch
Type: text/x-patch
Size: 2601 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220920/ed12b68d/attachment.bin>


More information about the lldb-commits mailing list