This revision was automatically updated to reflect the committed changes.
Closed by commit rL258758: Set symbol types for function symbols loaded from 
PE/COFF (authored by amccarth).

Changed prior to commit:
  http://reviews.llvm.org/D16563?vs=45933&id=45935#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D16563

Files:
  lldb/trunk/include/lldb/Core/RangeMap.h
  lldb/trunk/include/lldb/Symbol/Symtab.h
  lldb/trunk/source/Core/Module.cpp
  lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
  lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
  lldb/trunk/source/Symbol/Symtab.cpp

Index: lldb/trunk/source/Symbol/Symtab.cpp
===================================================================
--- lldb/trunk/source/Symbol/Symtab.cpp
+++ lldb/trunk/source/Symbol/Symtab.cpp
@@ -1074,7 +1074,7 @@
 }
 
 void
-Symtab::ForEachSymbolContainingFileAddresss (addr_t file_addr, std::function <bool(Symbol *)> const &callback)
+Symtab::ForEachSymbolContainingFileAddress(addr_t file_addr, std::function<bool(Symbol *)> const &callback)
 {
     Mutex::Locker locker (m_mutex);
 
@@ -1084,9 +1084,9 @@
     std::vector<uint32_t> all_addr_indexes;
 
     // Get all symbols with file_addr
-    const size_t addr_match_count = m_file_addr_to_index.FindEntryIndexesThatContains(file_addr, all_addr_indexes);
+    const size_t addr_match_count = m_file_addr_to_index.FindEntryIndexesThatContain(file_addr, all_addr_indexes);
 
-    for (size_t i=0; i<addr_match_count; ++i)
+    for (size_t i = 0; i < addr_match_count; ++i)
     {
         if (!callback(SymbolAtIndex(all_addr_indexes[i])))
         break;
Index: lldb/trunk/source/Core/Module.cpp
===================================================================
--- lldb/trunk/source/Core/Module.cpp
+++ lldb/trunk/source/Core/Module.cpp
@@ -560,14 +560,16 @@
             if (symtab && so_addr.IsSectionOffset())
             {
                 Symbol *matching_symbol = nullptr;
-                symtab->ForEachSymbolContainingFileAddresss (so_addr.GetFileAddress(), [&matching_symbol](Symbol *symbol) -> bool {
-                    if (symbol->GetType() != eSymbolTypeInvalid)
-                    {
-                        matching_symbol = symbol;
-                        return false; // Stop iterating
-                    }
-                    return true; // Keep iterating
-                });
+
+                symtab->ForEachSymbolContainingFileAddress(so_addr.GetFileAddress(),
+                                                           [&matching_symbol](Symbol *symbol) -> bool {
+                                                               if (symbol->GetType() != eSymbolTypeInvalid)
+                                                               {
+                                                                   matching_symbol = symbol;
+                                                                   return false; // Stop iterating
+                                                               }
+                                                               return true; // Keep iterating
+                                                           });
                 sc.symbol = matching_symbol;
                 if (!sc.symbol &&
                     resolve_scope & eSymbolContextFunction && !(resolved_flags & eSymbolContextFunction))
Index: lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
===================================================================
--- lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
+++ lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp
@@ -169,6 +169,18 @@
     return magic == IMAGE_DOS_SIGNATURE;
 }
 
+lldb::SymbolType
+ObjectFilePECOFF::MapSymbolType(uint16_t coff_symbol_type)
+{
+    // TODO:  We need to complete this mapping of COFF symbol types to LLDB ones.
+    // For now, here's a hack to make sure our function have types.
+    const auto complex_type = coff_symbol_type >> llvm::COFF::SCT_COMPLEX_TYPE_SHIFT;
+    if (complex_type == llvm::COFF::IMAGE_SYM_DTYPE_FUNCTION)
+    {
+        return lldb::eSymbolTypeCode;
+    }
+    return lldb::eSymbolTypeInvalid;
+}
 
 ObjectFilePECOFF::ObjectFilePECOFF (const lldb::ModuleSP &module_sp, 
                                     DataBufferSP& data_sp,
@@ -534,8 +546,8 @@
             {
                 const uint32_t symbol_size = 18;
                 const uint32_t addr_byte_size = GetAddressByteSize ();
-                const size_t symbol_data_size = num_syms * symbol_size; 
-                // Include the 4 bytes string table size at the end of the symbols
+                const size_t symbol_data_size = num_syms * symbol_size;
+                // Include the 4-byte string table size at the end of the symbols
                 DataBufferSP symtab_data_sp(m_file.ReadFileContents (m_coff_header.symoff, symbol_data_size + 4));
                 DataExtractor symtab_data (symtab_data_sp, GetByteOrder(), addr_byte_size);
                 lldb::offset_t offset = symbol_data_size;
@@ -556,8 +568,8 @@
                     coff_symbol_t symbol;
                     const uint32_t symbol_offset = offset;
                     const char *symbol_name_cstr = NULL;
-                    // If the first 4 bytes of the symbol string are zero, then we
-                    // it is followed by a 4 byte string table offset. Else these
+                    // If the first 4 bytes of the symbol string are zero, then they
+                    // are followed by a 4-byte string table offset. Else these
                     // 8 bytes contain the symbol name
                     if (symtab_data.GetU32 (&offset) == 0)
                     {
@@ -586,6 +598,7 @@
                     {
                         Address symbol_addr(sect_list->GetSectionAtIndex(symbol.sect-1), symbol.value);
                         symbols[i].GetAddressRef() = symbol_addr;
+                        symbols[i].SetType(MapSymbolType(symbol.type));
                     }
 
                     if (symbol.naux > 0)
Index: lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
===================================================================
--- lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
+++ lldb/trunk/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h
@@ -101,7 +101,10 @@
 
     static bool
     MagicBytesMatch (lldb::DataBufferSP& data_sp);
-    
+
+    static lldb::SymbolType
+    MapSymbolType(uint16_t coff_symbol_type);
+
     bool
     ParseHeader() override;
     
@@ -116,7 +119,7 @@
     
     uint32_t
     GetAddressByteSize() const override;
-    
+
 //    virtual lldb_private::AddressClass
 //    GetAddressClass (lldb::addr_t file_addr);
 
Index: lldb/trunk/include/lldb/Core/RangeMap.h
===================================================================
--- lldb/trunk/include/lldb/Core/RangeMap.h
+++ lldb/trunk/include/lldb/Core/RangeMap.h
@@ -1218,19 +1218,19 @@
         }
 
         uint32_t
-        FindEntryIndexesThatContains (B addr, std::vector<uint32_t> &indexes) const
+        FindEntryIndexesThatContain(B addr, std::vector<uint32_t> &indexes) const
         {
 #ifdef ASSERT_RANGEMAP_ARE_SORTED
             assert (IsSorted());
 #endif
 
             if (!m_entries.empty())
             {
                 typename Collection::const_iterator pos;
-                for(pos = m_entries.begin(); pos != m_entries.end(); pos++)
+                for (const auto &entry : m_entries)
                 {
-                    if (pos->Contains(addr))
-                        indexes.push_back (pos->data);
+                    if (entry.Contains(addr))
+                        indexes.push_back(entry.data);
                 }
             }
             return indexes.size() ;
Index: lldb/trunk/include/lldb/Symbol/Symtab.h
===================================================================
--- lldb/trunk/include/lldb/Symbol/Symtab.h
+++ lldb/trunk/include/lldb/Symbol/Symtab.h
@@ -81,7 +81,7 @@
             Symbol *    FindFirstSymbolWithNameAndType (const ConstString &name, lldb::SymbolType symbol_type, Debug symbol_debug_type, Visibility symbol_visibility);
             Symbol *    FindSymbolContainingFileAddress (lldb::addr_t file_addr, const uint32_t* indexes, uint32_t num_indexes);
             Symbol *    FindSymbolContainingFileAddress (lldb::addr_t file_addr);
-            void        ForEachSymbolContainingFileAddresss (lldb::addr_t file_addr, std::function <bool(Symbol *)> const &callback);
+            void        ForEachSymbolContainingFileAddress(lldb::addr_t file_addr, std::function<bool(Symbol *)> const &callback);
             size_t      FindFunctionSymbols (const ConstString &name, uint32_t name_type_mask, SymbolContextList& sc_list);
             void        CalculateSymbolSizes ();
 
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to