[Lldb-commits] [lldb] r260767 - Fix stripping of _ when looking for symbols in IRExecutionUnit.

Sean Callanan via lldb-commits lldb-commits at lists.llvm.org
Fri Feb 12 15:55:14 PST 2016


Author: spyffe
Date: Fri Feb 12 17:55:13 2016
New Revision: 260767

URL: http://llvm.org/viewvc/llvm-project?rev=260767&view=rev
Log:
Fix stripping of _ when looking for symbols in IRExecutionUnit.

Previously we would try both versions of a symbol -- the one with _ in it and
the one without -- in all cases, because we didn't know what the current
platform's policy was.  However, stripping _ is only necessary on platforms
where _ is the prefix for global symbols.

There's an API that does this, though, on llvm::DataLayout, so this patch fixes
IRExecutionUnit to use that API to determine whether or not to strip _ from the
symbol or not.

Modified:
    lldb/trunk/include/lldb/Expression/IRExecutionUnit.h
    lldb/trunk/source/Expression/IRExecutionUnit.cpp

Modified: lldb/trunk/include/lldb/Expression/IRExecutionUnit.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/IRExecutionUnit.h?rev=260767&r1=260766&r2=260767&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/IRExecutionUnit.h (original)
+++ lldb/trunk/include/lldb/Expression/IRExecutionUnit.h Fri Feb 12 17:55:13 2016
@@ -134,15 +134,9 @@ public:
     lldb::ModuleSP
     GetJITModule ();
         
-    static lldb::addr_t
-    FindSymbol(const ConstString &name,
-               const SymbolContext &sc);
-    
     lldb::addr_t
-    FindSymbol(const ConstString &name)
-    {
-        return FindSymbol(name, m_sym_ctx);
-    }
+    FindSymbol(const ConstString &name);
+
 private:
     //------------------------------------------------------------------
     /// Look up the object in m_address_map that contains a given address,
@@ -212,6 +206,25 @@ private:
     DisassembleFunction (Stream &stream,
                          lldb::ProcessSP &process_sp);
 
+    struct SearchSpec;
+    
+    void
+    CollectCandidateCNames(std::vector<SearchSpec> &C_specs,
+                           const ConstString &name);
+    
+    void
+    CollectCandidateCPlusPlusNames(std::vector<SearchSpec> &CPP_specs,
+                                   const std::vector<SearchSpec> &C_specs,
+                                   const SymbolContext &sc);
+    
+    lldb::addr_t
+    FindInSymbols(const std::vector<SearchSpec> &specs,
+                  const lldb_private::SymbolContext &sc);
+    
+    lldb::addr_t
+    FindInRuntimes(const std::vector<SearchSpec> &specs,
+                   const lldb_private::SymbolContext &sc);
+    
     void
     ReportSymbolLookupError(const ConstString &name);
 
@@ -402,6 +415,8 @@ private:
 
     lldb::addr_t                            m_function_load_addr;
     lldb::addr_t                            m_function_end_load_addr;
+    
+    bool                                    m_strip_underscore;     ///< True for platforms where global symbols have a _ prefix
 };
 
 } // namespace lldb_private

Modified: lldb/trunk/source/Expression/IRExecutionUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/IRExecutionUnit.cpp?rev=260767&r1=260766&r2=260767&view=diff
==============================================================================
--- lldb/trunk/source/Expression/IRExecutionUnit.cpp (original)
+++ lldb/trunk/source/Expression/IRExecutionUnit.cpp Fri Feb 12 17:55:13 2016
@@ -325,6 +325,8 @@ IRExecutionUnit::GetRunnableInfo(Error &
                                                                mAttrs);
 
     m_execution_engine_ap.reset(builder.create(target_machine));
+    
+    m_strip_underscore = (m_execution_engine_ap->getDataLayout().getGlobalPrefix() == '_');
 
     if (!m_execution_engine_ap.get())
     {
@@ -644,64 +646,6 @@ IRExecutionUnit::MemoryManager::allocate
     return return_value;
 }
 
-static void
-FindCodeSymbolInContext(const ConstString &name,
-                        const SymbolContext &sym_ctx,
-                        uint32_t name_type_mask,
-                        SymbolContextList &sc_list)
-{
-    sc_list.Clear();
-    SymbolContextList temp_sc_list;
-    if (sym_ctx.module_sp)
-        sym_ctx.module_sp->FindFunctions(name,
-                                         NULL,
-                                         name_type_mask,
-                                         true,  // include_symbols
-                                         false, // include_inlines
-                                         true,  // append
-                                         temp_sc_list);
-    if (temp_sc_list.GetSize() == 0)
-    {
-        if (sym_ctx.target_sp)
-            sym_ctx.target_sp->GetImages().FindFunctions(name,
-                                                         name_type_mask,
-                                                         true,  // include_symbols
-                                                         false, // include_inlines
-                                                         true,  // append
-                                                         temp_sc_list);
-    }
-
-    SymbolContextList internal_symbol_sc_list;
-    unsigned temp_sc_list_size = temp_sc_list.GetSize();
-    for (unsigned i = 0; i < temp_sc_list_size; i++)
-    {
-        SymbolContext sc;
-        temp_sc_list.GetContextAtIndex(i, sc);
-        if (sc.function)
-        {
-            sc_list.Append(sc);
-        }
-        else if (sc.symbol)
-        {
-            if (sc.symbol->IsExternal())
-            {
-                sc_list.Append(sc);
-            }
-            else
-            {
-                internal_symbol_sc_list.Append(sc);
-            }
-        }
-    }
-
-    // If we had internal symbols and we didn't find any external symbols or
-    // functions in debug info, then fallback to the internal symbols
-    if (sc_list.GetSize() == 0 && internal_symbol_sc_list.GetSize())
-    {
-        sc_list = internal_symbol_sc_list;
-    }
-}
-
 static ConstString
 FindBestAlternateMangledName(const ConstString &demangled,
                              const lldb::LanguageType &lang_type,
@@ -756,7 +700,7 @@ FindBestAlternateMangledName(const Const
         return ConstString();
 }
 
-struct SearchSpec
+struct IRExecutionUnit::SearchSpec
 {
     ConstString name;
     uint32_t    mask;
@@ -768,16 +712,16 @@ struct SearchSpec
     }
 };
 
-static void
-CollectCandidateCNames(std::vector<SearchSpec> &C_specs, const ConstString &name)
+void
+IRExecutionUnit::CollectCandidateCNames(std::vector<IRExecutionUnit::SearchSpec> &C_specs, const ConstString &name)
 {
+    if (m_strip_underscore && name.AsCString()[0] == '_')
+        C_specs.insert(C_specs.begin(), ConstString(&name.AsCString()[1]));
     C_specs.push_back(SearchSpec(name));
-    if (name.AsCString()[0] == '_')
-        C_specs.push_back(ConstString(&name.AsCString()[1]));
 }
 
-static void
-CollectCandidateCPlusPlusNames(std::vector<SearchSpec> &CPP_specs, const std::vector<SearchSpec> &C_specs, const SymbolContext &sc)
+void
+IRExecutionUnit::CollectCandidateCPlusPlusNames(std::vector<IRExecutionUnit::SearchSpec> &CPP_specs, const std::vector<SearchSpec> &C_specs, const SymbolContext &sc)
 {
     for (const SearchSpec &C_spec : C_specs)
     {
@@ -822,8 +766,8 @@ CollectCandidateCPlusPlusNames(std::vect
     }
 }
 
-static lldb::addr_t
-FindInSymbols(const std::vector<SearchSpec> &specs, const lldb_private::SymbolContext &sc)
+lldb::addr_t
+IRExecutionUnit::FindInSymbols(const std::vector<IRExecutionUnit::SearchSpec> &specs, const lldb_private::SymbolContext &sc)
 {
     for (const SearchSpec &spec : specs)
     {
@@ -902,8 +846,8 @@ FindInSymbols(const std::vector<SearchSp
     return LLDB_INVALID_ADDRESS;
 }
 
-static lldb::addr_t
-FindInRuntimes(const std::vector<SearchSpec> &specs, const lldb_private::SymbolContext &sc)
+lldb::addr_t
+IRExecutionUnit::FindInRuntimes(const std::vector<SearchSpec> &specs, const lldb_private::SymbolContext &sc)
 {
     lldb::TargetSP target_sp = sc.target_sp;
     
@@ -936,21 +880,21 @@ FindInRuntimes(const std::vector<SearchS
 }
 
 lldb::addr_t
-IRExecutionUnit::FindSymbol(const lldb_private::ConstString &name, const lldb_private::SymbolContext &sc)
+IRExecutionUnit::FindSymbol(const lldb_private::ConstString &name)
 {
     std::vector<SearchSpec> candidate_C_names;
     std::vector<SearchSpec> candidate_CPlusPlus_names;
     
     CollectCandidateCNames(candidate_C_names, name);
 
-    lldb::addr_t ret = FindInSymbols(candidate_C_names, sc);
+    lldb::addr_t ret = FindInSymbols(candidate_C_names, m_sym_ctx);
     if (ret == LLDB_INVALID_ADDRESS)
-        ret = FindInRuntimes(candidate_C_names, sc);
+        ret = FindInRuntimes(candidate_C_names, m_sym_ctx);
     
     if (ret == LLDB_INVALID_ADDRESS)
     {
-        CollectCandidateCPlusPlusNames(candidate_CPlusPlus_names, candidate_C_names, sc);
-        ret = FindInSymbols(candidate_CPlusPlus_names, sc);
+        CollectCandidateCPlusPlusNames(candidate_CPlusPlus_names, candidate_C_names, m_sym_ctx);
+        ret = FindInSymbols(candidate_CPlusPlus_names, m_sym_ctx);
     }
     
     return ret;




More information about the lldb-commits mailing list