Better scheme to lookup alternate mangled name when looking up function address.

Summary:
This change is relevant for inferiors compiled with GCC. GCC does not
emit complete debug info for std::basic_string<...>, and consequently, Clang
(the LLDB compiler) does not generate correct mangled names for certain
functions.

This change removes the hard-coded alternate names in
ItaniumABILanguageRuntime.cpp.

Before the hard-coded names were put in ItaniumABILanguageRuntime.cpp, one could
not evaluate std::string methods (ex. std::string::length). After putting in
the hard-coded names, one could evaluate them. However, it did not still
enable one to call methods on, say for example, std::vector<string>.
This change makes that possible.

There is some amount of incompleteness in this change. Consider the
following example:

std::string hello("hello"), world("world");
std::map<std::string, std::string> m;
m[hello] = world;

One can still not evaluate the expression "m[hello]" in LLDB. Will
address this issue in another pass.

Reviewers: jingham, vharron, evgeny777, spyffe, dawn

Subscribers: clayborg, dawn, lldb-commits

Differential Revision: http://reviews.llvm.org/D12809

llvm-svn: 257113
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index 0ed4d05..423b73d 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -2927,6 +2927,40 @@
     return sc_list.GetSize() - original_size;
 }
 
+void
+SymbolFileDWARF::GetMangledNamesForFunction (const std::string &scope_qualified_name,
+                                             std::vector<ConstString> &mangled_names)
+{
+    DWARFDebugInfo* info = DebugInfo();
+    uint32_t num_comp_units = 0;
+    if (info)
+        num_comp_units = info->GetNumCompileUnits();
+
+    for (uint32_t i = 0; i < num_comp_units; i++)
+    {
+        DWARFCompileUnit *cu = info->GetCompileUnitAtIndex(i);
+        if (cu == nullptr)
+            continue;
+
+        SymbolFileDWARFDwo *dwo = cu->GetDwoSymbolFile();
+        if (dwo)
+            dwo->GetMangledNamesForFunction(scope_qualified_name, mangled_names);
+    }
+
+    NameToOffsetMap::iterator iter = m_function_scope_qualified_name_map.find(scope_qualified_name);
+    if (iter == m_function_scope_qualified_name_map.end())
+        return;
+
+    DIERefSetSP set_sp = (*iter).second;
+    std::set<DIERef>::iterator set_iter;
+    for (set_iter = set_sp->begin(); set_iter != set_sp->end(); set_iter++)
+    {
+        DWARFDIE die = DebugInfo()->GetDIE (*set_iter);
+        mangled_names.push_back(ConstString(die.GetMangledName()));
+    }
+}
+
+
 uint32_t
 SymbolFileDWARF::FindTypes (const SymbolContext& sc, 
                             const ConstString &name, 
@@ -3751,6 +3785,24 @@
                     TypeList* type_list = GetTypeList();
                     if (type_list)
                         type_list->Insert(type_sp);
+
+                    if (die.Tag() == DW_TAG_subprogram)
+                    {
+                        DIERef die_ref = die.GetDIERef();
+                        std::string scope_qualified_name(GetDeclContextForUID(die.GetID()).GetScopeQualifiedName().AsCString(""));
+                        if (scope_qualified_name.size())
+                        {
+                            NameToOffsetMap::iterator iter = m_function_scope_qualified_name_map.find(scope_qualified_name);
+                            if (iter != m_function_scope_qualified_name_map.end())
+                                (*iter).second->insert(die_ref);
+                            else
+                            {
+                                DIERefSetSP new_set(new std::set<DIERef>);
+                                new_set->insert(die_ref);
+                                m_function_scope_qualified_name_map.emplace(std::make_pair(scope_qualified_name, new_set));
+                            }
+                        }
+                    }
                 }
             }
         }