[Lldb-commits] [lldb] r145733 - /lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Greg Clayton gclayton at apple.com
Fri Dec 2 16:27:06 PST 2011


Author: gclayton
Date: Fri Dec  2 18:27:05 2011
New Revision: 145733

URL: http://llvm.org/viewvc/llvm-project?rev=145733&view=rev
Log:
<rdar://problem/10522194>

Fixed an issue where if we have the DWARF equivalent of:

struct foo;

class foo { ... };

Or vice versa, we wouldn't be able to find the complete type. Since many
compilers allow forward declarations to have struct and definitions to have
class, we need to be able to deal with both cases. This commit fixes this in
the DWARF parser.


Modified:
    lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp?rev=145733&r1=145732&r2=145733&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Fri Dec  2 18:27:05 2011
@@ -3804,7 +3804,7 @@
     
     const size_t num_matches = die_offsets.size();
 
-    const dw_tag_t type_tag = die->Tag();
+    const dw_tag_t die_tag = die->Tag();
     
     DWARFCompileUnit* type_cu = NULL;
     const DWARFDebugInfoEntry* type_die = NULL;
@@ -3818,31 +3818,59 @@
             
             if (type_die)
             {
-                if (type_die != die && type_die->Tag() == type_tag)
+                bool try_resolving_type = false;
+
+                // Don't try and resolve the DIE we are looking for with the DIE itself!
+                if (type_die != die)
                 {
-                    // Hold off on comparing parent DIE tags until
-                    // we know what happens with stuff in namespaces
-                    // for gcc and clang...
-                    //DWARFDebugInfoEntry *parent_die = die->GetParent();
-                    //DWARFDebugInfoEntry *parent_type_die = type_die->GetParent();
-                    //if (parent_die->Tag() == parent_type_die->Tag())
-                    {
-                        Type *resolved_type = ResolveType (type_cu, type_die, false);
-                        if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
-                        {
-                            DEBUG_PRINTF ("resolved 0x%8.8llx (cu 0x%8.8llx) from %s to 0x%8.8llx (cu 0x%8.8llx)\n",
-                                          MakeUserID(die->GetOffset()), 
-                                          MakeUserID(curr_cu->GetOffset()), 
-                                          m_obj_file->GetFileSpec().GetFilename().AsCString(),
-                                          MakeUserID(type_die->GetOffset()), 
-                                          MakeUserID(type_cu->GetOffset()));
-                            
-                            m_die_to_type[die] = resolved_type;
-                            type_sp = resolved_type;
+                    const dw_tag_t type_die_tag = type_die->Tag();
+                    // Make sure the tags match
+                    if (type_die_tag == die_tag)
+                    {
+                        // The tags match, lets try resolving this type
+                        try_resolving_type = true;
+                    }
+                    else
+                    {
+                        // The tags don't match, but we need to watch our for a
+                        // forward declaration for a struct and ("struct foo")
+                        // ends up being a class ("class foo { ... };") or
+                        // vice versa.
+                        switch (type_die_tag)
+                        {
+                        case DW_TAG_class_type:
+                            // We had a "class foo", see if we ended up with a "struct foo { ... };"
+                            try_resolving_type = (die_tag == DW_TAG_structure_type);
+                            break;
+                        case DW_TAG_structure_type:
+                            // We had a "struct foo", see if we ended up with a "class foo { ... };"
+                            try_resolving_type = (die_tag == DW_TAG_class_type);
+                            break;
+                        default:
+                            // Tags don't match, don't event try to resolve
+                            // using this type whose name matches....
                             break;
                         }
                     }
                 }
+                        
+                if (try_resolving_type)
+                {
+                    Type *resolved_type = ResolveType (type_cu, type_die, false);
+                    if (resolved_type && resolved_type != DIE_IS_BEING_PARSED)
+                    {
+                        DEBUG_PRINTF ("resolved 0x%8.8llx (cu 0x%8.8llx) from %s to 0x%8.8llx (cu 0x%8.8llx)\n",
+                                      MakeUserID(die->GetOffset()), 
+                                      MakeUserID(curr_cu->GetOffset()), 
+                                      m_obj_file->GetFileSpec().GetFilename().AsCString(),
+                                      MakeUserID(type_die->GetOffset()), 
+                                      MakeUserID(type_cu->GetOffset()));
+                        
+                        m_die_to_type[die] = resolved_type;
+                        type_sp = resolved_type;
+                        break;
+                    }
+                }
             }
             else
             {





More information about the lldb-commits mailing list