<p dir="ltr">The doc comment for SortTypeList() is wrong.</p>
<div class="gmail_quote">On Sep 23, 2015 12:20 AM, "Ravitheja Addepally via lldb-commits" <<a href="mailto:lldb-commits@lists.llvm.org">lldb-commits@lists.llvm.org</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: ravitheja<br>
Date: Wed Sep 23 02:19:02 2015<br>
New Revision: 248366<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=248366&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=248366&view=rev</a><br>
Log:<br>
Testcase and fix for bug 24074<br>
<br>
Summary:<br>
In bug 24074, the type information is not shown<br>
correctly. This commit  includes the following -<br>
-> Changes for displaying correct type based on<br>
   current lexical scope for the command "image<br>
   lookup -t"<br>
-> The corresponding testcase.<br>
<br>
Reviewers: jingham, ovyalov, spyffe, richard.mitton, clayborg<br>
<br>
Differential Revision: <a href="http://reviews.llvm.org/D12404" rel="noreferrer" target="_blank">http://reviews.llvm.org/D12404</a><br>
<br>
Added:<br>
    lldb/trunk/include/lldb/Symbol/TypeMap.h<br>
    lldb/trunk/source/Symbol/TypeMap.cpp<br>
    lldb/trunk/test/lang/c/typedef/<br>
    lldb/trunk/test/lang/c/typedef/Makefile<br>
    lldb/trunk/test/lang/c/typedef/Testtypedef.py<br>
    lldb/trunk/test/lang/c/typedef/main.c<br>
Modified:<br>
    lldb/trunk/include/lldb/Core/Module.h<br>
    lldb/trunk/include/lldb/Symbol/SymbolContext.h<br>
    lldb/trunk/include/lldb/Symbol/SymbolFile.h<br>
    lldb/trunk/include/lldb/Symbol/SymbolVendor.h<br>
    lldb/trunk/include/lldb/Symbol/TypeList.h<br>
    lldb/trunk/include/lldb/lldb-forward.h<br>
    lldb/trunk/source/Commands/CommandObjectTarget.cpp<br>
    lldb/trunk/source/Core/Module.cpp<br>
    lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp<br>
    lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h<br>
    lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp<br>
    lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h<br>
    lldb/trunk/source/Symbol/CMakeLists.txt<br>
    lldb/trunk/source/Symbol/SymbolContext.cpp<br>
    lldb/trunk/source/Symbol/SymbolFile.cpp<br>
    lldb/trunk/source/Symbol/SymbolVendor.cpp<br>
    lldb/trunk/source/Symbol/TypeList.cpp<br>
<br>
Modified: lldb/trunk/include/lldb/Core/Module.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Module.h?rev=248366&r1=248365&r2=248366&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Module.h?rev=248366&r1=248365&r2=248366&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/include/lldb/Core/Module.h (original)<br>
+++ lldb/trunk/include/lldb/Core/Module.h Wed Sep 23 02:19:02 2015<br>
@@ -1193,7 +1193,7 @@ private:<br>
                     const CompilerDeclContext *parent_decl_ctx,<br>
                     bool append,<br>
                     size_t max_matches,<br>
-                    TypeList& types);<br>
+                    TypeMap& types);<br>
<br>
<br>
     DISALLOW_COPY_AND_ASSIGN (Module);<br>
<br>
Modified: lldb/trunk/include/lldb/Symbol/SymbolContext.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/SymbolContext.h?rev=248366&r1=248365&r2=248366&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/SymbolContext.h?rev=248366&r1=248365&r2=248366&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/include/lldb/Symbol/SymbolContext.h (original)<br>
+++ lldb/trunk/include/lldb/Symbol/SymbolContext.h Wed Sep 23 02:19:02 2015<br>
@@ -299,6 +299,27 @@ public:<br>
                            ConstString &language_object_name);<br>
<br>
     //------------------------------------------------------------------<br>
+    /// If this symbol context represents a function that is a method,<br>
+    /// return true and provide information about the method.<br>
+    ///<br>
+    /// @param[out] language<br>
+    ///     If \b true is returned, the language for the method.<br>
+    ///<br>
+    /// @param[out] is_instance_method<br>
+    ///     If \b true is returned, \b true if this is a instance method,<br>
+    ///     \b false if this is a static/class function.<br>
+    ///<br>
+    /// @param[out] language_object_name<br>
+    ///     If \b true is returned, the name of the artificial variable<br>
+    ///     for the language ("this" for C++, "self" for ObjC).<br>
+    ///<br>
+    /// @return<br>
+    ///     \b True if this symbol context represents a function that<br>
+    ///     is a method of a class, \b false otherwise.<br>
+    //------------------------------------------------------------------<br>
+    void<br>
+       SortTypeList(TypeMap &type_map, TypeList &type_list) const;<br>
+    //------------------------------------------------------------------<br>
     /// Find a name of the innermost function for the symbol context.<br>
     ///<br>
     /// For instance, if the symbol context contains an inlined block,<br>
<br>
Modified: lldb/trunk/include/lldb/Symbol/SymbolFile.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/SymbolFile.h?rev=248366&r1=248365&r2=248366&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/SymbolFile.h?rev=248366&r1=248365&r2=248366&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/include/lldb/Symbol/SymbolFile.h (original)<br>
+++ lldb/trunk/include/lldb/Symbol/SymbolFile.h Wed Sep 23 02:19:02 2015<br>
@@ -141,7 +141,7 @@ public:<br>
     virtual uint32_t        FindGlobalVariables (const RegularExpression& regex, bool append, uint32_t max_matches, VariableList& variables);<br>
     virtual uint32_t        FindFunctions (const ConstString &name, const CompilerDeclContext *parent_decl_ctx, uint32_t name_type_mask, bool include_inlines, bool append, SymbolContextList& sc_list);<br>
     virtual uint32_t        FindFunctions (const RegularExpression& regex, bool include_inlines, bool append, SymbolContextList& sc_list);<br>
-    virtual uint32_t        FindTypes (const SymbolContext& sc, const ConstString &name, const CompilerDeclContext *parent_decl_ctx, bool append, uint32_t max_matches, TypeList& types);<br>
+    virtual uint32_t        FindTypes (const SymbolContext& sc, const ConstString &name, const CompilerDeclContext *parent_decl_ctx, bool append, uint32_t max_matches, TypeMap& types);<br>
 //  virtual uint32_t        FindTypes (const SymbolContext& sc, const RegularExpression& regex, bool append, uint32_t max_matches, TypeList& types) = 0;<br>
     virtual TypeList *      GetTypeList ();<br>
     virtual size_t          GetTypes (lldb_private::SymbolContextScope *sc_scope,<br>
<br>
Modified: lldb/trunk/include/lldb/Symbol/SymbolVendor.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/SymbolVendor.h?rev=248366&r1=248365&r2=248366&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/SymbolVendor.h?rev=248366&r1=248365&r2=248366&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/include/lldb/Symbol/SymbolVendor.h (original)<br>
+++ lldb/trunk/include/lldb/Symbol/SymbolVendor.h Wed Sep 23 02:19:02 2015<br>
@@ -16,6 +16,7 @@<br>
 #include "lldb/Core/ModuleChild.h"<br>
 #include "lldb/Core/PluginInterface.h"<br>
 #include "lldb/Symbol/TypeList.h"<br>
+#include "lldb/Symbol/TypeMap.h"<br>
<br>
 namespace lldb_private {<br>
<br>
@@ -125,7 +126,7 @@ public:<br>
                const CompilerDeclContext *parent_decl_ctx,<br>
                bool append,<br>
                size_t max_matches,<br>
-               TypeList& types);<br>
+               TypeMap& types);<br>
<br>
     virtual CompilerDeclContext<br>
     FindNamespace (const SymbolContext& sc,<br>
<br>
Modified: lldb/trunk/include/lldb/Symbol/TypeList.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/TypeList.h?rev=248366&r1=248365&r2=248366&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/TypeList.h?rev=248366&r1=248365&r2=248366&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/include/lldb/Symbol/TypeList.h (original)<br>
+++ lldb/trunk/include/lldb/Symbol/TypeList.h Wed Sep 23 02:19:02 2015<br>
@@ -13,7 +13,7 @@<br>
 #include "lldb/lldb-private.h"<br>
 #include "lldb/Symbol/Type.h"<br>
 #include "lldb/Utility/Iterable.h"<br>
-#include <map><br>
+#include <vector><br>
 #include <functional><br>
<br>
 namespace lldb_private {<br>
@@ -24,7 +24,7 @@ public:<br>
     //------------------------------------------------------------------<br>
     // Constructors and Destructors<br>
     //------------------------------------------------------------------<br>
-    TypeList();<br>
+       TypeList();<br>
<br>
     virtual<br>
     ~TypeList();<br>
@@ -44,17 +44,14 @@ public:<br>
     void<br>
     Insert (const lldb::TypeSP& type);<br>
<br>
-    bool<br>
-    InsertUnique (const lldb::TypeSP& type);<br>
-<br>
     uint32_t<br>
     GetSize() const;<br>
<br>
     lldb::TypeSP<br>
     GetTypeAtIndex(uint32_t idx);<br>
<br>
-    typedef std::multimap<lldb::user_id_t, lldb::TypeSP> collection;<br>
-    typedef AdaptedIterable<collection, lldb::TypeSP, map_adapter> TypeIterable;<br>
+    typedef std::vector<lldb::TypeSP> collection;<br>
+    typedef AdaptedIterable<collection, lldb::TypeSP, vector_adapter> TypeIterable;<br>
<br>
     TypeIterable<br>
     Types ()<br>
@@ -68,8 +65,6 @@ public:<br>
     void<br>
     ForEach (std::function <bool(lldb::TypeSP &type_sp)> const &callback);<br>
<br>
-    bool<br>
-    RemoveTypeWithUID (lldb::user_id_t uid);<br>
<br>
     void<br>
     RemoveMismatchedTypes (const char *qualified_typename,<br>
<br>
Added: lldb/trunk/include/lldb/Symbol/TypeMap.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/TypeMap.h?rev=248366&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/TypeMap.h?rev=248366&view=auto</a><br>
==============================================================================<br>
--- lldb/trunk/include/lldb/Symbol/TypeMap.h (added)<br>
+++ lldb/trunk/include/lldb/Symbol/TypeMap.h Wed Sep 23 02:19:02 2015<br>
@@ -0,0 +1,98 @@<br>
+//===-- TypeMap.h ----------------------------------------------*- C++ -*-===//<br>
+//<br>
+//                     The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#ifndef liblldb_TypeMap_h_<br>
+#define liblldb_TypeMap_h_<br>
+<br>
+#include "lldb/lldb-private.h"<br>
+#include "lldb/Symbol/Type.h"<br>
+#include "lldb/Utility/Iterable.h"<br>
+#include <map><br>
+#include <functional><br>
+<br>
+namespace lldb_private {<br>
+<br>
+class TypeMap<br>
+{<br>
+public:<br>
+    //------------------------------------------------------------------<br>
+    // Constructors and Destructors<br>
+    //------------------------------------------------------------------<br>
+       TypeMap();<br>
+<br>
+    virtual<br>
+    ~TypeMap();<br>
+<br>
+    void<br>
+    Clear();<br>
+<br>
+    void<br>
+    Dump(Stream *s, bool show_context);<br>
+<br>
+//    lldb::TypeSP<br>
+//    FindType(lldb::user_id_t uid);<br>
+<br>
+    TypeMap<br>
+    FindTypes(const ConstString &name);<br>
+<br>
+    void<br>
+    Insert (const lldb::TypeSP& type);<br>
+<br>
+    bool<br>
+    InsertUnique (const lldb::TypeSP& type);<br>
+<br>
+    uint32_t<br>
+    GetSize() const;<br>
+<br>
+    lldb::TypeSP<br>
+    GetTypeAtIndex(uint32_t idx);<br>
+<br>
+    typedef std::multimap<lldb::user_id_t, lldb::TypeSP> collection;<br>
+    typedef AdaptedIterable<collection, lldb::TypeSP, map_adapter> TypeIterable;<br>
+<br>
+    TypeIterable<br>
+    Types ()<br>
+    {<br>
+        return TypeIterable(m_types);<br>
+    }<br>
+<br>
+    void<br>
+    ForEach (std::function <bool(const lldb::TypeSP &type_sp)> const &callback) const;<br>
+<br>
+    void<br>
+    ForEach (std::function <bool(lldb::TypeSP &type_sp)> const &callback);<br>
+<br>
+    bool<br>
+    RemoveTypeWithUID (lldb::user_id_t uid);<br>
+<br>
+    void<br>
+    RemoveMismatchedTypes (const char *qualified_typename,<br>
+                           bool exact_match);<br>
+<br>
+    void<br>
+    RemoveMismatchedTypes (const std::string &type_scope,<br>
+                           const std::string &type_basename,<br>
+                           lldb::TypeClass type_class,<br>
+                           bool exact_match);<br>
+<br>
+    void<br>
+    RemoveMismatchedTypes (lldb::TypeClass type_class);<br>
+<br>
+private:<br>
+    typedef collection::iterator iterator;<br>
+    typedef collection::const_iterator const_iterator;<br>
+<br>
+    collection m_types;<br>
+<br>
+    DISALLOW_COPY_AND_ASSIGN (TypeMap);<br>
+};<br>
+<br>
+} // namespace lldb_private<br>
+<br>
+#endif  // liblldb_TypeMap_h_<br>
<br>
Modified: lldb/trunk/include/lldb/lldb-forward.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-forward.h?rev=248366&r1=248365&r2=248366&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-forward.h?rev=248366&r1=248365&r2=248366&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/include/lldb/lldb-forward.h (original)<br>
+++ lldb/trunk/include/lldb/lldb-forward.h Wed Sep 23 02:19:02 2015<br>
@@ -254,6 +254,7 @@ class   TypeAndOrName;<br>
 class   TypeCategoryMap;<br>
 class   TypeImpl;<br>
 class   TypeList;<br>
+class   TypeMap;<br>
 class   TypeListImpl;<br>
 class   TypeMemberImpl;<br>
 class   TypeMemberFunctionImpl;<br>
<br>
Modified: lldb/trunk/source/Commands/CommandObjectTarget.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectTarget.cpp?rev=248366&r1=248365&r2=248366&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectTarget.cpp?rev=248366&r1=248365&r2=248366&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/Commands/CommandObjectTarget.cpp (original)<br>
+++ lldb/trunk/source/Commands/CommandObjectTarget.cpp Wed Sep 23 02:19:02 2015<br>
@@ -1918,7 +1918,6 @@ LookupTypeHere (CommandInterpreter &inte<br>
         strm.PutCString("Best match found in ");<br>
         DumpFullpath (strm, &sym_ctx.module_sp->GetFileSpec(), 0);<br>
         strm.PutCString(":\n");<br>
-<br>
         TypeSP type_sp (type_list.GetTypeAtIndex(0));<br>
         if (type_sp)<br>
         {<br>
<br>
Modified: lldb/trunk/source/Core/Module.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Module.cpp?rev=248366&r1=248365&r2=248366&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Module.cpp?rev=248366&r1=248365&r2=248366&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/Core/Module.cpp (original)<br>
+++ lldb/trunk/source/Core/Module.cpp Wed Sep 23 02:19:02 2015<br>
@@ -36,6 +36,7 @@<br>
 #include "lldb/Target/Target.h"<br>
 #include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h"<br>
 #include "Plugins/Language/ObjC/ObjCLanguage.h"<br>
+#include "lldb/Symbol/TypeMap.h"<br>
<br>
 #include "Plugins/ObjectFile/JIT/ObjectFileJIT.h"<br>
<br>
@@ -940,7 +941,7 @@ Module::FindTypes_Impl (const SymbolCont<br>
                         const CompilerDeclContext *parent_decl_ctx,<br>
                         bool append,<br>
                         size_t max_matches,<br>
-                        TypeList& types)<br>
+                        TypeMap& types)<br>
 {<br>
     Timer scoped_timer(__PRETTY_FUNCTION__, __PRETTY_FUNCTION__);<br>
     if (sc.module_sp.get() == NULL || sc.module_sp.get() == this)<br>
@@ -960,7 +961,11 @@ Module::FindTypesInNamespace (const Symb<br>
                               TypeList& type_list)<br>
 {<br>
     const bool append = true;<br>
-    return FindTypes_Impl(sc, type_name, parent_decl_ctx, append, max_matches, type_list);<br>
+    TypeMap types_map;<br>
+    size_t num_types = FindTypes_Impl(sc, type_name, parent_decl_ctx, append, max_matches, types_map);<br>
+    if (num_types > 0)<br>
+        sc.SortTypeList(types_map, type_list);<br>
+    return num_types;<br>
 }<br>
<br>
 lldb::TypeSP<br>
@@ -989,6 +994,7 @@ Module::FindTypes (const SymbolContext&<br>
     std::string type_basename;<br>
     const bool append = true;<br>
     TypeClass type_class = eTypeClassAny;<br>
+    TypeMap typesmap;<br>
     if (Type::GetTypeScopeAndBasename (type_name_cstr, type_scope, type_basename, type_class))<br>
     {<br>
         // Check if "name" starts with "::" which means the qualified type starts<br>
@@ -1002,10 +1008,10 @@ Module::FindTypes (const SymbolContext&<br>
             exact_match = true;<br>
         }<br>
         ConstString type_basename_const_str (type_basename.c_str());<br>
-        if (FindTypes_Impl(sc, type_basename_const_str, NULL, append, max_matches, types))<br>
+        if (FindTypes_Impl(sc, type_basename_const_str, NULL, append, max_matches, typesmap))<br>
         {<br>
-            types.RemoveMismatchedTypes (type_scope, type_basename, type_class, exact_match);<br>
-            num_matches = types.GetSize();<br>
+            typesmap.RemoveMismatchedTypes (type_scope, type_basename, type_class, exact_match);<br>
+            num_matches = typesmap.GetSize();<br>
         }<br>
     }<br>
     else<br>
@@ -1015,18 +1021,18 @@ Module::FindTypes (const SymbolContext&<br>
         {<br>
             // The "type_name_cstr" will have been modified if we have a valid type class<br>
             // prefix (like "struct", "class", "union", "typedef" etc).<br>
-            FindTypes_Impl(sc, ConstString(type_name_cstr), NULL, append, max_matches, types);<br>
-            types.RemoveMismatchedTypes (type_class);<br>
-            num_matches = types.GetSize();<br>
+            FindTypes_Impl(sc, ConstString(type_name_cstr), NULL, append, max_matches, typesmap);<br>
+            typesmap.RemoveMismatchedTypes (type_class);<br>
+            num_matches = typesmap.GetSize();<br>
         }<br>
         else<br>
         {<br>
-            num_matches = FindTypes_Impl(sc, name, NULL, append, max_matches, types);<br>
+            num_matches = FindTypes_Impl(sc, name, NULL, append, max_matches, typesmap);<br>
         }<br>
     }<br>
-<br>
+    if (num_matches > 0)<br>
+        sc.SortTypeList(typesmap, types);<br>
     return num_matches;<br>
-<br>
 }<br>
<br>
 SymbolVendor*<br>
<br>
Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp?rev=248366&r1=248365&r2=248366&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp?rev=248366&r1=248365&r2=248366&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (original)<br>
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Wed Sep 23 02:19:02 2015<br>
@@ -43,6 +43,7 @@<br>
 #include "lldb/Symbol/SymbolVendor.h"<br>
 #include "lldb/Symbol/TypeSystem.h"<br>
 #include "lldb/Symbol/VariableList.h"<br>
+#include "lldb/Symbol/TypeMap.h"<br>
<br>
 #include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h"<br>
 #include "Plugins/Language/ObjC/ObjCLanguage.h"<br>
@@ -2840,7 +2841,7 @@ SymbolFileDWARF::FindTypes (const Symbol<br>
                             const CompilerDeclContext *parent_decl_ctx,<br>
                             bool append,<br>
                             uint32_t max_matches,<br>
-                            TypeList& types)<br>
+                            TypeMap& types)<br>
 {<br>
     DWARFDebugInfo* info = DebugInfo();<br>
     if (info == NULL)<br>
@@ -3054,6 +3055,17 @@ SymbolFileDWARF::GetTypeForDIE (const DW<br>
             CompileUnit* lldb_cu = GetCompUnitForDWARFCompUnit(die.GetCU());<br>
             assert (lldb_cu);<br>
             SymbolContext sc(lldb_cu);<br>
+            const DWARFDebugInfoEntry* parent_die = die.GetParent().GetDIE();<br>
+            while (parent_die != nullptr)<br>
+                {<br>
+                    if (parent_die->Tag() == DW_TAG_subprogram)<br>
+                        break;<br>
+                    parent_die = parent_die->GetParent();<br>
+                }<br>
+            SymbolContext sc_backup = sc;<br>
+            if (parent_die != nullptr && !GetFunction(DWARFDIE(die.GetCU(),parent_die), sc))<br>
+                sc = sc_backup;<br>
+<br>
             type_sp = ParseType(sc, die, NULL);<br>
         }<br>
         else if (type_ptr != DIE_IS_BEING_PARSED)<br>
<br>
Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h?rev=248366&r1=248365&r2=248366&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h?rev=248366&r1=248365&r2=248366&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h (original)<br>
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h Wed Sep 23 02:19:02 2015<br>
@@ -207,7 +207,7 @@ public:<br>
                const lldb_private::CompilerDeclContext *parent_decl_ctx,<br>
                bool append,<br>
                uint32_t max_matches,<br>
-               lldb_private::TypeList& types) override;<br>
+               lldb_private::TypeMap& types) override;<br>
<br>
     lldb_private::TypeList *<br>
     GetTypeList () override;<br>
<br>
Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp?rev=248366&r1=248365&r2=248366&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp?rev=248366&r1=248365&r2=248366&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp (original)<br>
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp Wed Sep 23 02:19:02 2015<br>
@@ -28,6 +28,7 @@<br>
 #include "lldb/Symbol/LineTable.h"<br>
 #include "lldb/Symbol/ObjectFile.h"<br>
 #include "lldb/Symbol/SymbolVendor.h"<br>
+#include "lldb/Symbol/TypeMap.h"<br>
 #include "lldb/Symbol/VariableList.h"<br>
<br>
 #include "LogChannelDWARF.h"<br>
@@ -1295,7 +1296,7 @@ SymbolFileDWARFDebugMap::FindTypes<br>
     const CompilerDeclContext *parent_decl_ctx,<br>
     bool append,<br>
     uint32_t max_matches,<br>
-    TypeList& types<br>
+    TypeMap& types<br>
 )<br>
 {<br>
     if (!append)<br>
<br>
Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h?rev=248366&r1=248365&r2=248366&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h?rev=248366&r1=248365&r2=248366&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h (original)<br>
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h Wed Sep 23 02:19:02 2015<br>
@@ -79,7 +79,7 @@ public:<br>
     uint32_t        FindGlobalVariables (const lldb_private::RegularExpression& regex, bool append, uint32_t max_matches, lldb_private::VariableList& variables) override;<br>
     uint32_t        FindFunctions (const lldb_private::ConstString &name, const lldb_private::CompilerDeclContext *parent_decl_ctx, uint32_t name_type_mask, bool include_inlines, bool append, lldb_private::SymbolContextList& sc_list) override;<br>
     uint32_t        FindFunctions (const lldb_private::RegularExpression& regex, bool include_inlines, bool append, lldb_private::SymbolContextList& sc_list) override;<br>
-    uint32_t        FindTypes (const lldb_private::SymbolContext& sc, const lldb_private::ConstString &name, const lldb_private::CompilerDeclContext *parent_decl_ctx, bool append, uint32_t max_matches, lldb_private::TypeList& types) override;<br>
+    uint32_t        FindTypes (const lldb_private::SymbolContext& sc, const lldb_private::ConstString &name, const lldb_private::CompilerDeclContext *parent_decl_ctx, bool append, uint32_t max_matches, lldb_private::TypeMap& types) override;<br>
     lldb_private::CompilerDeclContext<br>
                     FindNamespace (const lldb_private::SymbolContext& sc,<br>
                                    const lldb_private::ConstString &name,<br>
<br>
Modified: lldb/trunk/source/Symbol/CMakeLists.txt<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/CMakeLists.txt?rev=248366&r1=248365&r2=248366&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/CMakeLists.txt?rev=248366&r1=248365&r2=248366&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/Symbol/CMakeLists.txt (original)<br>
+++ lldb/trunk/source/Symbol/CMakeLists.txt Wed Sep 23 02:19:02 2015<br>
@@ -24,6 +24,7 @@ add_lldb_library(lldbSymbol<br>
   Symtab.cpp<br>
   Type.cpp<br>
   TypeList.cpp<br>
+  TypeMap.cpp<br>
   TypeSystem.cpp<br>
   UnwindPlan.cpp<br>
   UnwindTable.cpp<br>
<br>
Modified: lldb/trunk/source/Symbol/SymbolContext.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/SymbolContext.cpp?rev=248366&r1=248365&r2=248366&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/SymbolContext.cpp?rev=248366&r1=248365&r2=248366&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/Symbol/SymbolContext.cpp (original)<br>
+++ lldb/trunk/source/Symbol/SymbolContext.cpp Wed Sep 23 02:19:02 2015<br>
@@ -659,6 +659,171 @@ SymbolContext::GetFunctionMethodInfo (ll<br>
     return false;<br>
 }<br>
<br>
+class TypeMoveMatchingBlock<br>
+{<br>
+public:<br>
+       TypeMoveMatchingBlock(Block * block, TypeMap &typem, TypeList &typel) :<br>
+               curr_block(block),type_map(typem),type_list(typel)<br>
+    {<br>
+    }<br>
+<br>
+    bool<br>
+    operator() (const lldb::TypeSP& type)<br>
+    {<br>
+       if (type && type->GetSymbolContextScope() != nullptr && curr_block == type->GetSymbolContextScope()->CalculateSymbolContextBlock())<br>
+       {<br>
+               type_list.Insert(type);<br>
+               type_map.RemoveTypeWithUID(type->GetID());<br>
+               return false;<br>
+       }<br>
+        return true;<br>
+    }<br>
+<br>
+private:<br>
+    const Block * const curr_block;<br>
+    TypeMap &type_map;<br>
+    TypeList &type_list;<br>
+};<br>
+<br>
+class TypeMoveMatchingFunction<br>
+{<br>
+public:<br>
+       TypeMoveMatchingFunction(Function * block, TypeMap &typem, TypeList &typel) :<br>
+               func(block),type_map(typem),type_list(typel)<br>
+    {<br>
+    }<br>
+<br>
+    bool<br>
+    operator() (const lldb::TypeSP& type)<br>
+    {<br>
+       if (type && type->GetSymbolContextScope() != nullptr && func == type->GetSymbolContextScope()->CalculateSymbolContextFunction())<br>
+       {<br>
+           type_list.Insert(type);<br>
+           type_map.RemoveTypeWithUID(type->GetID());<br>
+           return false;<br>
+       }<br>
+        return true;<br>
+    }<br>
+<br>
+private:<br>
+    const Function * const func;<br>
+    TypeMap &type_map;<br>
+    TypeList &type_list;<br>
+};<br>
+<br>
+class TypeMoveMatchingCompileUnit<br>
+{<br>
+public:<br>
+       TypeMoveMatchingCompileUnit(CompileUnit * cunit, TypeMap &typem, TypeList &typel) :<br>
+               comp_unit(cunit),type_map(typem),type_list(typel)<br>
+    {<br>
+    }<br>
+<br>
+    bool<br>
+    operator() (const lldb::TypeSP& type)<br>
+    {<br>
+       if (type && type->GetSymbolContextScope() != nullptr && comp_unit == type->GetSymbolContextScope()->CalculateSymbolContextCompileUnit())<br>
+       {<br>
+           type_list.Insert(type);<br>
+           type_map.RemoveTypeWithUID(type->GetID());<br>
+           return false;<br>
+       }<br>
+       return true;<br>
+    }<br>
+<br>
+private:<br>
+    const CompileUnit * const comp_unit;<br>
+    TypeMap &type_map;<br>
+    TypeList &type_list;<br>
+};<br>
+<br>
+class TypeMoveMatchingModule<br>
+{<br>
+public:<br>
+       TypeMoveMatchingModule(lldb::ModuleSP modsp, TypeMap &typem, TypeList &typel) :<br>
+               modulesp(modsp),type_map(typem),type_list(typel)<br>
+    {<br>
+    }<br>
+<br>
+    bool<br>
+    operator() (const lldb::TypeSP& type)<br>
+    {<br>
+       if (type && type->GetSymbolContextScope() != nullptr && modulesp.get() == type->GetSymbolContextScope()->CalculateSymbolContextModule().get())<br>
+       {<br>
+           type_list.Insert(type);<br>
+           type_map.RemoveTypeWithUID(type->GetID());<br>
+           return false;<br>
+       }<br>
+        return true;<br>
+    }<br>
+<br>
+private:<br>
+    lldb::ModuleSP modulesp;<br>
+    TypeMap &type_map;<br>
+    TypeList &type_list;<br>
+};<br>
+<br>
+class TypeMaptoList<br>
+{<br>
+public:<br>
+       TypeMaptoList(TypeMap &typem, TypeList &typel) :<br>
+               type_map(typem),type_list(typel)<br>
+    {<br>
+    }<br>
+<br>
+    bool<br>
+    operator() (const lldb::TypeSP& type)<br>
+    {<br>
+       if(type)<br>
+       {<br>
+            type_list.Insert(type);<br>
+            type_map.RemoveTypeWithUID(type->GetID());<br>
+       }<br>
+        return true;<br>
+    }<br>
+<br>
+private:<br>
+    TypeMap &type_map;<br>
+    TypeList &type_list;<br>
+};<br>
+<br>
+void<br>
+SymbolContext::SortTypeList(TypeMap &type_map, TypeList &type_list ) const<br>
+{<br>
+       Block * curr_block = block;<br>
+    bool isInlinedblock = false;<br>
+    if(curr_block != nullptr && curr_block->GetContainingInlinedBlock() != nullptr)<br>
+       isInlinedblock = true;<br>
+<br>
+       while (curr_block != nullptr && !isInlinedblock)<br>
+    {<br>
+               TypeMoveMatchingBlock callbackBlock (curr_block, type_map, type_list);<br>
+               type_map.ForEach(callbackBlock);<br>
+           curr_block = curr_block->GetParent();<br>
+       }<br>
+    if(function != nullptr && type_map.GetSize() > 0)<br>
+    {<br>
+       TypeMoveMatchingFunction callbackFunction (function, type_map, type_list);<br>
+       type_map.ForEach(callbackFunction);<br>
+    }<br>
+    if(comp_unit != nullptr && type_map.GetSize() > 0)<br>
+    {<br>
+       TypeMoveMatchingCompileUnit callbackCompileUnit (comp_unit, type_map, type_list);<br>
+       type_map.ForEach(callbackCompileUnit);<br>
+    }<br>
+    if(module_sp && type_map.GetSize() > 0)<br>
+    {<br>
+       TypeMoveMatchingModule callbackModule (module_sp, type_map, type_list);<br>
+       type_map.ForEach(callbackModule);<br>
+    }<br>
+    if(type_map.GetSize() > 0)<br>
+    {<br>
+       TypeMaptoList callbackM2L (type_map, type_list);<br>
+       type_map.ForEach(callbackM2L);<br>
+    }<br>
+       return ;<br>
+}<br>
+<br>
 ConstString<br>
 SymbolContext::GetFunctionName (Mangled::NamePreference preference) const<br>
 {<br>
<br>
Modified: lldb/trunk/source/Symbol/SymbolFile.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/SymbolFile.cpp?rev=248366&r1=248365&r2=248366&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/SymbolFile.cpp?rev=248366&r1=248365&r2=248366&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/Symbol/SymbolFile.cpp (original)<br>
+++ lldb/trunk/source/Symbol/SymbolFile.cpp Wed Sep 23 02:19:02 2015<br>
@@ -15,7 +15,7 @@<br>
 #include "lldb/Core/PluginManager.h"<br>
 #include "lldb/Core/StreamString.h"<br>
 #include "lldb/Symbol/ObjectFile.h"<br>
-#include "lldb/Symbol/TypeList.h"<br>
+#include "lldb/Symbol/TypeMap.h"<br>
 #include "lldb/Symbol/TypeSystem.h"<br>
 #include "lldb/Symbol/VariableList.h"<br>
<br>
@@ -135,7 +135,7 @@ SymbolFile::FindFunctions (const Regular<br>
 }<br>
<br>
 uint32_t<br>
-SymbolFile::FindTypes (const SymbolContext& sc, const ConstString &name, const CompilerDeclContext *parent_decl_ctx, bool append, uint32_t max_matches, TypeList& types)<br>
+SymbolFile::FindTypes (const SymbolContext& sc, const ConstString &name, const CompilerDeclContext *parent_decl_ctx, bool append, uint32_t max_matches, TypeMap& types)<br>
 {<br>
     if (!append)<br>
         types.Clear();<br>
<br>
Modified: lldb/trunk/source/Symbol/SymbolVendor.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/SymbolVendor.cpp?rev=248366&r1=248365&r2=248366&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/SymbolVendor.cpp?rev=248366&r1=248365&r2=248366&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/Symbol/SymbolVendor.cpp (original)<br>
+++ lldb/trunk/source/Symbol/SymbolVendor.cpp Wed Sep 23 02:19:02 2015<br>
@@ -346,7 +346,7 @@ SymbolVendor::FindFunctions(const Regula<br>
<br>
<br>
 size_t<br>
-SymbolVendor::FindTypes (const SymbolContext& sc, const ConstString &name, const CompilerDeclContext *parent_decl_ctx, bool append, size_t max_matches, TypeList& types)<br>
+SymbolVendor::FindTypes (const SymbolContext& sc, const ConstString &name, const CompilerDeclContext *parent_decl_ctx, bool append, size_t max_matches, TypeMap& types)<br>
 {<br>
     ModuleSP module_sp(GetModule());<br>
     if (module_sp)<br>
<br>
Modified: lldb/trunk/source/Symbol/TypeList.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/TypeList.cpp?rev=248366&r1=248365&r2=248366&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/TypeList.cpp?rev=248366&r1=248365&r2=248366&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/source/Symbol/TypeList.cpp (original)<br>
+++ lldb/trunk/source/Symbol/TypeList.cpp Wed Sep 23 02:19:02 2015<br>
@@ -42,26 +42,7 @@ TypeList::Insert (const TypeSP& type_sp)<br>
 {<br>
     // Just push each type on the back for now. We will worry about uniquing later<br>
     if (type_sp)<br>
-        m_types.insert(std::make_pair(type_sp->GetID(), type_sp));<br>
-}<br>
-<br>
-<br>
-bool<br>
-TypeList::InsertUnique (const TypeSP& type_sp)<br>
-{<br>
-    if (type_sp)<br>
-    {<br>
-        user_id_t type_uid = type_sp->GetID();<br>
-        iterator pos, end = m_types.end();<br>
-<br>
-        for (pos = m_types.find(type_uid); pos != end && pos->second->GetID() == type_uid; ++pos)<br>
-        {<br>
-            if (pos->second.get() == type_sp.get())<br>
-                return false;<br>
-        }<br>
-    }<br>
-    Insert (type_sp);<br>
-    return true;<br>
+        m_types.push_back(type_sp);<br>
 }<br>
<br>
 //----------------------------------------------------------------------<br>
@@ -116,7 +97,7 @@ TypeList::GetTypeAtIndex(uint32_t idx)<br>
     for (pos = m_types.begin(), end = m_types.end(); pos != end; ++pos)<br>
     {<br>
         if (i == 0)<br>
-            return pos->second;<br>
+            return *pos;<br>
         --i;<br>
     }<br>
     return TypeSP();<br>
@@ -127,7 +108,7 @@ TypeList::ForEach (std::function <bool(c<br>
 {<br>
     for (auto pos = m_types.begin(), end = m_types.end(); pos != end; ++pos)<br>
     {<br>
-        if (!callback(pos->second))<br>
+        if (!callback(*pos))<br>
             break;<br>
     }<br>
 }<br>
@@ -137,32 +118,17 @@ TypeList::ForEach (std::function <bool(l<br>
 {<br>
     for (auto pos = m_types.begin(), end = m_types.end(); pos != end; ++pos)<br>
     {<br>
-        if (!callback(pos->second))<br>
+        if (!callback(*pos))<br>
             break;<br>
     }<br>
 }<br>
<br>
-<br>
-bool<br>
-TypeList::RemoveTypeWithUID (user_id_t uid)<br>
-{<br>
-    iterator pos = m_types.find(uid);<br>
-<br>
-    if (pos != m_types.end())<br>
-    {<br>
-        m_types.erase(pos);<br>
-        return true;<br>
-    }<br>
-    return false;<br>
-}<br>
-<br>
-<br>
 void<br>
 TypeList::Dump(Stream *s, bool show_context)<br>
 {<br>
     for (iterator pos = m_types.begin(), end = m_types.end(); pos != end; ++pos)<br>
     {<br>
-        pos->second->Dump(s, show_context);<br>
+        pos->get()->Dump(s, show_context);<br>
     }<br>
 }<br>
<br>
@@ -197,7 +163,7 @@ TypeList::RemoveMismatchedTypes (const s<br>
<br>
     for (pos = m_types.begin(); pos != end; ++pos)<br>
     {<br>
-        Type* the_type = pos->second.get();<br>
+        Type* the_type = pos->get();<br>
         bool keep_match = false;<br>
         TypeClass match_type_class = eTypeClassAny;<br>
<br>
@@ -269,7 +235,7 @@ TypeList::RemoveMismatchedTypes (const s<br>
<br>
         if (keep_match)<br>
         {<br>
-            matching_types.insert (*pos);<br>
+            matching_types.push_back(*pos);<br>
         }<br>
     }<br>
     m_types.swap(matching_types);<br>
@@ -291,10 +257,10 @@ TypeList::RemoveMismatchedTypes (TypeCla<br>
<br>
     for (pos = m_types.begin(); pos != end; ++pos)<br>
     {<br>
-        Type* the_type = pos->second.get();<br>
+        Type* the_type = pos->get();<br>
         TypeClass match_type_class = the_type->GetForwardCompilerType ().GetTypeClass ();<br>
         if (match_type_class & type_class)<br>
-            matching_types.insert (*pos);<br>
+            matching_types.push_back (*pos);<br>
     }<br>
     m_types.swap(matching_types);<br>
 }<br>
<br>
Added: lldb/trunk/source/Symbol/TypeMap.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/TypeMap.cpp?rev=248366&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/TypeMap.cpp?rev=248366&view=auto</a><br>
==============================================================================<br>
--- lldb/trunk/source/Symbol/TypeMap.cpp (added)<br>
+++ lldb/trunk/source/Symbol/TypeMap.cpp Wed Sep 23 02:19:02 2015<br>
@@ -0,0 +1,313 @@<br>
+//===-- TypeMap.cpp --------------------------------------------*- C++ -*-===//<br>
+//<br>
+//                     The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+<br>
+// C Includes<br>
+// C++ Includes<br>
+#include <vector><br>
+<br>
+// Other libraries and framework includes<br>
+#include "clang/AST/ASTConsumer.h"<br>
+#include "clang/AST/ASTContext.h"<br>
+#include "clang/AST/Decl.h"<br>
+#include "clang/AST/DeclCXX.h"<br>
+#include "clang/AST/DeclGroup.h"<br>
+<br>
+#include "clang/Basic/Builtins.h"<br>
+#include "clang/Basic/IdentifierTable.h"<br>
+#include "clang/Basic/LangOptions.h"<br>
+#include "clang/Basic/SourceManager.h"<br>
+#include "clang/Basic/TargetInfo.h"<br>
+<br>
+#include "llvm/Support/FormattedStream.h"<br>
+#include "llvm/Support/raw_ostream.h"<br>
+<br>
+// Project includes<br>
+#include "lldb/Symbol/SymbolFile.h"<br>
+#include "lldb/Symbol/SymbolVendor.h"<br>
+#include "lldb/Symbol/Type.h"<br>
+#include "lldb/Symbol/TypeMap.h"<br>
+<br>
+using namespace lldb;<br>
+using namespace lldb_private;<br>
+using namespace clang;<br>
+<br>
+TypeMap::TypeMap() :<br>
+    m_types ()<br>
+{<br>
+}<br>
+<br>
+//----------------------------------------------------------------------<br>
+// Destructor<br>
+//----------------------------------------------------------------------<br>
+TypeMap::~TypeMap()<br>
+{<br>
+}<br>
+<br>
+void<br>
+TypeMap::Insert (const TypeSP& type_sp)<br>
+{<br>
+    // Just push each type on the back for now. We will worry about uniquing later<br>
+    if (type_sp)<br>
+        m_types.insert(std::make_pair(type_sp->GetID(), type_sp));<br>
+}<br>
+<br>
+<br>
+bool<br>
+TypeMap::InsertUnique (const TypeSP& type_sp)<br>
+{<br>
+    if (type_sp)<br>
+    {<br>
+        user_id_t type_uid = type_sp->GetID();<br>
+        iterator pos, end = m_types.end();<br>
+<br>
+        for (pos = m_types.find(type_uid); pos != end && pos->second->GetID() == type_uid; ++pos)<br>
+        {<br>
+            if (pos->second.get() == type_sp.get())<br>
+                return false;<br>
+        }<br>
+    }<br>
+    Insert (type_sp);<br>
+    return true;<br>
+}<br>
+<br>
+//----------------------------------------------------------------------<br>
+// Find a base type by its unique ID.<br>
+//----------------------------------------------------------------------<br>
+//TypeSP<br>
+//TypeMap::FindType(lldb::user_id_t uid)<br>
+//{<br>
+//    iterator pos = m_types.find(uid);<br>
+//    if (pos != m_types.end())<br>
+//        return pos->second;<br>
+//    return TypeSP();<br>
+//}<br>
+<br>
+//----------------------------------------------------------------------<br>
+// Find a type by name.<br>
+//----------------------------------------------------------------------<br>
+//TypeMap<br>
+//TypeMap::FindTypes (const ConstString &name)<br>
+//{<br>
+//    // Do we ever need to make a lookup by name map? Here we are doing<br>
+//    // a linear search which isn't going to be fast.<br>
+//    TypeMap types(m_ast.getTargetInfo()->getTriple().getTriple().c_str());<br>
+//    iterator pos, end;<br>
+//    for (pos = m_types.begin(), end = m_types.end(); pos != end; ++pos)<br>
+//        if (pos->second->GetName() == name)<br>
+//            types.Insert (pos->second);<br>
+//    return types;<br>
+//}<br>
+<br>
+void<br>
+TypeMap::Clear()<br>
+{<br>
+    m_types.clear();<br>
+}<br>
+<br>
+uint32_t<br>
+TypeMap::GetSize() const<br>
+{<br>
+    return m_types.size();<br>
+}<br>
+<br>
+// GetTypeAtIndex isn't used a lot for large type lists, currently only for<br>
+// type lists that are returned for "image dump -t TYPENAME" commands and other<br>
+// simple symbol queries that grab the first result...<br>
+<br>
+TypeSP<br>
+TypeMap::GetTypeAtIndex(uint32_t idx)<br>
+{<br>
+    iterator pos, end;<br>
+    uint32_t i = idx;<br>
+    for (pos = m_types.begin(), end = m_types.end(); pos != end; ++pos)<br>
+    {<br>
+        if (i == 0)<br>
+            return pos->second;<br>
+        --i;<br>
+    }<br>
+    return TypeSP();<br>
+}<br>
+<br>
+void<br>
+TypeMap::ForEach (std::function <bool(const lldb::TypeSP &type_sp)> const &callback) const<br>
+{<br>
+    for (auto pos = m_types.begin(), end = m_types.end(); pos != end; ++pos)<br>
+    {<br>
+        if (!callback(pos->second))<br>
+            break;<br>
+    }<br>
+}<br>
+<br>
+void<br>
+TypeMap::ForEach (std::function <bool(lldb::TypeSP &type_sp)> const &callback)<br>
+{<br>
+    for (auto pos = m_types.begin(), end = m_types.end(); pos != end; ++pos)<br>
+    {<br>
+        if (!callback(pos->second))<br>
+            break;<br>
+    }<br>
+}<br>
+<br>
+<br>
+bool<br>
+TypeMap::RemoveTypeWithUID (user_id_t uid)<br>
+{<br>
+    iterator pos = m_types.find(uid);<br>
+<br>
+    if (pos != m_types.end())<br>
+    {<br>
+        m_types.erase(pos);<br>
+        return true;<br>
+    }<br>
+    return false;<br>
+}<br>
+<br>
+<br>
+void<br>
+TypeMap::Dump(Stream *s, bool show_context)<br>
+{<br>
+    for (iterator pos = m_types.begin(), end = m_types.end(); pos != end; ++pos)<br>
+    {<br>
+        pos->second->Dump(s, show_context);<br>
+    }<br>
+}<br>
+<br>
+void<br>
+TypeMap::RemoveMismatchedTypes (const char *qualified_typename,<br>
+                                 bool exact_match)<br>
+{<br>
+    std::string type_scope;<br>
+    std::string type_basename;<br>
+    TypeClass type_class = eTypeClassAny;<br>
+    if (!Type::GetTypeScopeAndBasename (qualified_typename, type_scope, type_basename, type_class))<br>
+    {<br>
+        type_basename = qualified_typename;<br>
+        type_scope.clear();<br>
+    }<br>
+    return RemoveMismatchedTypes (type_scope, type_basename, type_class, exact_match);<br>
+}<br>
+<br>
+void<br>
+TypeMap::RemoveMismatchedTypes (const std::string &type_scope,<br>
+                                 const std::string &type_basename,<br>
+                                 TypeClass type_class,<br>
+                                 bool exact_match)<br>
+{<br>
+    // Our "collection" type currently is a std::map which doesn't<br>
+    // have any good way to iterate and remove items from the map<br>
+    // so we currently just make a new list and add all of the matching<br>
+    // types to it, and then swap it into m_types at the end<br>
+    collection matching_types;<br>
+<br>
+    iterator pos, end = m_types.end();<br>
+<br>
+    for (pos = m_types.begin(); pos != end; ++pos)<br>
+    {<br>
+        Type* the_type = pos->second.get();<br>
+        bool keep_match = false;<br>
+        TypeClass match_type_class = eTypeClassAny;<br>
+<br>
+        if (type_class != eTypeClassAny)<br>
+        {<br>
+            match_type_class = the_type->GetForwardCompilerType ().GetTypeClass ();<br>
+            if ((match_type_class & type_class) == 0)<br>
+                continue;<br>
+        }<br>
+<br>
+        ConstString match_type_name_const_str (the_type->GetQualifiedName());<br>
+        if (match_type_name_const_str)<br>
+        {<br>
+            const char *match_type_name = match_type_name_const_str.GetCString();<br>
+            std::string match_type_scope;<br>
+            std::string match_type_basename;<br>
+            if (Type::GetTypeScopeAndBasename (match_type_name,<br>
+                                               match_type_scope,<br>
+                                               match_type_basename,<br>
+                                               match_type_class))<br>
+            {<br>
+                if (match_type_basename == type_basename)<br>
+                {<br>
+                    const size_t type_scope_size = type_scope.size();<br>
+                    const size_t match_type_scope_size = match_type_scope.size();<br>
+                    if (exact_match || (type_scope_size == match_type_scope_size))<br>
+                    {<br>
+                        keep_match = match_type_scope == type_scope;<br>
+                    }<br>
+                    else<br>
+                    {<br>
+                        if (match_type_scope_size > type_scope_size)<br>
+                        {<br>
+                            const size_t type_scope_pos = match_type_scope.rfind(type_scope);<br>
+                            if (type_scope_pos == match_type_scope_size - type_scope_size)<br>
+                            {<br>
+                                if (type_scope_pos >= 2)<br>
+                                {<br>
+                                    // Our match scope ends with the type scope we were looking for,<br>
+                                    // but we need to make sure what comes before the matching<br>
+                                    // type scope is a namespace boundary in case we are trying to match:<br>
+                                    // type_basename = "d"<br>
+                                    // type_scope = "b::c::"<br>
+                                    // We want to match:<br>
+                                    //  match_type_scope "a::b::c::"<br>
+                                    // But not:<br>
+                                    //  match_type_scope "a::bb::c::"<br>
+                                    // So below we make sure what comes before "b::c::" in match_type_scope<br>
+                                    // is "::", or the namespace boundary<br>
+                                    if (match_type_scope[type_scope_pos - 1] == ':' &&<br>
+                                        match_type_scope[type_scope_pos - 2] == ':')<br>
+                                    {<br>
+                                        keep_match = true;<br>
+                                    }<br>
+                                }<br>
+                            }<br>
+                        }<br>
+                    }<br>
+                }<br>
+            }<br>
+            else<br>
+            {<br>
+                // The type we are currently looking at doesn't exists<br>
+                // in a namespace or class, so it only matches if there<br>
+                // is no type scope...<br>
+                keep_match = type_scope.empty() && type_basename.compare(match_type_name) == 0;<br>
+            }<br>
+        }<br>
+<br>
+        if (keep_match)<br>
+        {<br>
+            matching_types.insert (*pos);<br>
+        }<br>
+    }<br>
+    m_types.swap(matching_types);<br>
+}<br>
+<br>
+void<br>
+TypeMap::RemoveMismatchedTypes (TypeClass type_class)<br>
+{<br>
+    if (type_class == eTypeClassAny)<br>
+        return;<br>
+<br>
+    // Our "collection" type currently is a std::map which doesn't<br>
+    // have any good way to iterate and remove items from the map<br>
+    // so we currently just make a new list and add all of the matching<br>
+    // types to it, and then swap it into m_types at the end<br>
+    collection matching_types;<br>
+<br>
+    iterator pos, end = m_types.end();<br>
+<br>
+    for (pos = m_types.begin(); pos != end; ++pos)<br>
+    {<br>
+        Type* the_type = pos->second.get();<br>
+        TypeClass match_type_class = the_type->GetForwardCompilerType ().GetTypeClass ();<br>
+        if (match_type_class & type_class)<br>
+            matching_types.insert (*pos);<br>
+    }<br>
+    m_types.swap(matching_types);<br>
+}<br>
<br>
Added: lldb/trunk/test/lang/c/typedef/Makefile<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/c/typedef/Makefile?rev=248366&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/c/typedef/Makefile?rev=248366&view=auto</a><br>
==============================================================================<br>
--- lldb/trunk/test/lang/c/typedef/Makefile (added)<br>
+++ lldb/trunk/test/lang/c/typedef/Makefile Wed Sep 23 02:19:02 2015<br>
@@ -0,0 +1,5 @@<br>
+LEVEL = ../../../make<br>
+<br>
+C_SOURCES := main.c<br>
+<br>
+include $(LEVEL)/Makefile.rules<br>
<br>
Added: lldb/trunk/test/lang/c/typedef/Testtypedef.py<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/c/typedef/Testtypedef.py?rev=248366&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/c/typedef/Testtypedef.py?rev=248366&view=auto</a><br>
==============================================================================<br>
--- lldb/trunk/test/lang/c/typedef/Testtypedef.py (added)<br>
+++ lldb/trunk/test/lang/c/typedef/Testtypedef.py Wed Sep 23 02:19:02 2015<br>
@@ -0,0 +1,51 @@<br>
+"""Look up type information for typedefs of same name at different lexical scope and check for correct display."""<br>
+<br>
+import os, time<br>
+import unittest2<br>
+import lldb<br>
+from lldbtest import *<br>
+import lldbutil<br>
+<br>
+class TypedefTestCase(TestBase):<br>
+<br>
+    mydir = TestBase.compute_mydir(__file__)<br>
+<br>
+    @skipUnlessDarwin<br>
+    @dsym_test<br>
+    @expectedFailureClang("<a href="http://llvm.org/pr19238" rel="noreferrer" target="_blank">llvm.org/pr19238</a>")<br>
+    def test_with_dsym(self):<br>
+        """Test 'image lookup -t a' and check for correct display at different scopes."""<br>
+        self.buildDsym()<br>
+        self.image_lookup_for_multiple_typedefs()<br>
+<br>
+    @dwarf_test<br>
+    @expectedFailureClang("<a href="http://llvm.org/pr19238" rel="noreferrer" target="_blank">llvm.org/pr19238</a>")<br>
+    def test_with_dwarf(self):<br>
+        """Test 'image lookup -t a' and check for correct display at different scopes."""<br>
+        self.buildDwarf()<br>
+        self.image_lookup_for_multiple_typedefs()<br>
+<br>
+    def image_lookup_for_multiple_typedefs(self):<br>
+        """Test 'image lookup -t a' at different scopes and check for correct display."""<br>
+        exe = os.path.join(os.getcwd(), "a.out")<br>
+        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)<br>
+        typearray = ("float", "float", "char", "float", "int", "double", "float", "float")<br>
+        arraylen = len(typearray)+1<br>
+        for i in range(1,arraylen):<br>
+            loc_line = line_number('main.c', '// Set break point ' + str(i) + '.')<br>
+            lldbutil.run_break_set_by_file_and_line (self, "main.c",loc_line, num_expected_locations=1, loc_exact=True)<br>
+<br>
+        self.runCmd("run", RUN_SUCCEEDED)<br>
+<br>
+        for t in typearray:<br>
+            self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,<br>
+            substrs = ['stopped', 'stop reason = breakpoint'])<br>
+            self.expect("image lookup -t a", DATA_TYPES_DISPLAYED_CORRECTLY,<br>
+            substrs = ['name = "' + t + '"'])<br>
+            self.runCmd("continue")<br>
+<br>
+if __name__ == '__main__':<br>
+    import atexit<br>
+    lldb.SBDebugger.Initialize()<br>
+    atexit.register(lambda: lldb.SBDebugger.Terminate())<br>
+    unittest2.main()<br>
<br>
Added: lldb/trunk/test/lang/c/typedef/main.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/c/typedef/main.c?rev=248366&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lang/c/typedef/main.c?rev=248366&view=auto</a><br>
==============================================================================<br>
--- lldb/trunk/test/lang/c/typedef/main.c (added)<br>
+++ lldb/trunk/test/lang/c/typedef/main.c Wed Sep 23 02:19:02 2015<br>
@@ -0,0 +1,40 @@<br>
+//===-- main.c --------------------------------------------------*- C++ -*-===//<br>
+//<br>
+//                     The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+int main (int argc, char const *argv[])<br>
+{<br>
+    typedef float a;<br>
+    int i = 0; // Set break point 1.<br>
+    i++;<br>
+    a floatvariable = 2.7; // Set break point 2.<br>
+    {<br>
+        typedef char a;<br>
+        i++;<br>
+        a charvariable = 'a'; // Set break point 3.<br>
+    }<br>
+    {<br>
+        int c = 0;<br>
+        c++; // Set break point 4.<br>
+        for(i = 0 ; i < 1 ; i++)<br>
+        {<br>
+            typedef int a;<br>
+            a b;<br>
+            b = 7; // Set break point 5.<br>
+        }<br>
+        for(i = 0 ; i < 1 ; i++)<br>
+        {<br>
+            typedef double a;<br>
+            a b;<br>
+            b = 3.14; // Set break point 6.<br>
+        }<br>
+        c = 1; // Set break point 7.<br>
+    }<br>
+    floatvariable = 2.5;<br>
+    floatvariable = 2.8; // Set break point 8.<br>
+    return 0;<br>
+}<br>
<br>
<br>
_______________________________________________<br>
lldb-commits mailing list<br>
<a href="mailto:lldb-commits@lists.llvm.org">lldb-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits</a><br>
</blockquote></div>