[Lldb-commits] [PATCH] D134133: WIP: [lldb][COFF] Enhance symtab loading of symbol and export tables

2022-09-18 Thread Alvin Wong via Phabricator via lldb-commits
alvinhochun created this revision.
alvinhochun added reviewers: labath, DavidSpickett, mstorsjo.
Herald added a project: All.
alvinhochun requested review of this revision.
Herald added projects: LLDB, LLVM.
Herald added subscribers: llvm-commits, lldb-commits.

This reimplements `ObjectFilePECOFF::ParseSymtab` with the following
changes:

- When the image has both an export table and a COFF symbol table, the symbols 
obtained from the symbol table no longer get erased.
- Remove manual data extraction in favour of using what `COFFObjectFile` 
provides.
- Mark symbols from the export table as "External" instead of "Debug".
- Support DLL forwarder exports (marked as re-exported).
- Handle absolute symbols in the symbol table.
- Heuristically set some symbol types. Symbols in the symbol table starting in 
`__imp_` (dllimport IAT reference) or `.refptr.` (mingw stub) are marked as 
"Data", because their locations store a pointer address.
- When a symbol in the symbol table is a duplicate of an exported symbol, its 
info will be synchronized with the exported symbol, then it will be marked as 
"Additional" type to avoid unwanted repetition when used in commands like 
`disassemble`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134133

Files:
  lldb/include/lldb/Symbol/Symtab.h
  lldb/source/Commands/CommandObjectTarget.cpp
  lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
  lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
  lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp
  lldb/source/Symbol/Symtab.cpp
  llvm/include/llvm/Object/COFF.h

Index: llvm/include/llvm/Object/COFF.h
===
--- llvm/include/llvm/Object/COFF.h
+++ llvm/include/llvm/Object/COFF.h
@@ -914,6 +914,10 @@
 
   uint32_t getStringTableSize() const { return StringTableSize; }
 
+  const export_directory_table_entry *getExportTable() const {
+return ExportDirectory;
+  }
+
   const coff_load_configuration32 *getLoadConfig32() const {
 assert(!is64());
 return reinterpret_cast(LoadConfig);
Index: lldb/source/Symbol/Symtab.cpp
===
--- lldb/source/Symbol/Symtab.cpp
+++ lldb/source/Symbol/Symtab.cpp
@@ -61,6 +61,14 @@
   return m_symbols.empty() ? nullptr : &m_symbols[0];
 }
 
+Symbol *Symtab::Extend(size_t count) {
+  // Clients should grab the mutex from this symbol table and lock it manually
+  // when calling this function to avoid performance issues.
+  auto old_size = m_symbols.size();
+  m_symbols.resize(old_size + count);
+  return m_symbols.empty() ? nullptr : &m_symbols[old_size];
+}
+
 uint32_t Symtab::AddSymbol(const Symbol &symbol) {
   // Clients should grab the mutex from this symbol table and lock it manually
   // when calling this function to avoid performance issues.
@@ -809,6 +817,22 @@
   return nullptr;
 }
 
+bool Symtab::HasSymbolWithType(SymbolType symbol_type, Debug symbol_debug_type,
+   Visibility symbol_visibility) const {
+  std::lock_guard guard(m_mutex);
+
+  const size_t count = m_symbols.size();
+  for (size_t idx = 0; idx < count; ++idx) {
+if (symbol_type == eSymbolTypeAny ||
+m_symbols[idx].GetType() == symbol_type) {
+  if (CheckSymbolAtIndex(idx, symbol_debug_type, symbol_visibility)) {
+return true;
+  }
+}
+  }
+  return false;
+}
+
 void
 Symtab::FindAllSymbolsWithNameAndType(ConstString name,
   SymbolType symbol_type,
Index: lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp
===
--- lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp
+++ lldb/source/Plugins/SymbolFile/Symtab/SymbolFileSymtab.cpp
@@ -81,6 +81,11 @@
 abilities |= Functions;
   }
 
+  if (symtab->HasSymbolWithType(eSymbolTypeReExported, Symtab::eDebugAny,
+Symtab::eVisibilityAny)) {
+abilities |= Functions;
+  }
+
   if (symtab->AppendSymbolIndexesWithType(eSymbolTypeData,
   m_data_indexes)) {
 symtab->SortSymbolIndexesByValue(m_data_indexes, true);
Index: lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
===
--- lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
+++ lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
@@ -225,12 +225,6 @@
 data_dirs; // will contain num_data_dir_entries entries
   } coff_opt_header_t;
 
-  enum coff_data_dir_type {
-coff_data_dir_export_table = 0,
-coff_data_dir_import_table = 1,
-coff_data_dir_exception_table = 3
-  };
-
   typedef struct section_header {
 char name[8] = {};
 uint32_t vmsize = 0;  // Virtual Size
@@ -244,29 +238,6 @@
 uint32_t flags = 0;
   } section_header_t;
 
-  typedef struct coff_symbol {
-char name

[Lldb-commits] [lldb] 2078350 - Use std::make_unsigned_t (NFC)

2022-09-18 Thread Kazu Hirata via lldb-commits

Author: Kazu Hirata
Date: 2022-09-18T18:41:02-07:00
New Revision: 207835064514e968e40685bdc48b7bb0fc5c2779

URL: 
https://github.com/llvm/llvm-project/commit/207835064514e968e40685bdc48b7bb0fc5c2779
DIFF: 
https://github.com/llvm/llvm-project/commit/207835064514e968e40685bdc48b7bb0fc5c2779.diff

LOG: Use std::make_unsigned_t (NFC)

Added: 


Modified: 

lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
llvm/include/llvm/ADT/Bitfields.h

Removed: 




diff  --git 
a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp 
b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
index 7ee15fd7af4e5..c2c01d1e46053 100644
--- 
a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
+++ 
b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
@@ -772,7 +772,7 @@ template 
 static void fill_clamp(T &dest, U src, typename T::value_type fallback) {
   static_assert(std::is_unsigned::value,
 "Destination type must be unsigned.");
-  using UU = typename std::make_unsigned::type;
+  using UU = std::make_unsigned_t;
   constexpr auto T_max = std::numeric_limits::max();
   dest = src >= 0 && static_cast(src) <= T_max ? src : fallback;
 }

diff  --git a/llvm/include/llvm/ADT/Bitfields.h 
b/llvm/include/llvm/ADT/Bitfields.h
index aaf876d896d4c..045704a470b9c 100644
--- a/llvm/include/llvm/ADT/Bitfields.h
+++ b/llvm/include/llvm/ADT/Bitfields.h
@@ -96,7 +96,7 @@ template  struct BitPatterns {
   /// undefined operations over signed types (e.g. Bitwise shift operators).
   /// Moreover same size casting from unsigned to signed is well defined but 
not
   /// the other way around.
-  using Unsigned = typename std::make_unsigned::type;
+  using Unsigned = std::make_unsigned_t;
   static_assert(sizeof(Unsigned) == sizeof(T), "Types must have same size");
 
   static constexpr unsigned TypeBits = sizeof(Unsigned) * CHAR_BIT;



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits