[Lldb-commits] [lldb] r137436 - in /lldb/trunk/source: Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Plugins/SymbolFile/DWARF/SymbolFileDWARF.h Target/Thread.cpp

Greg Clayton gclayton at apple.com
Thu Aug 11 23:47:55 PDT 2011


Author: gclayton
Date: Fri Aug 12 01:47:54 2011
New Revision: 137436

URL: http://llvm.org/viewvc/llvm-project?rev=137436&view=rev
Log:
Fixed some issues with parsing C++ methods where our detection
was failing if the DWARF was laid out in a certain way. The way
we detect C++ classes is now more robust so that a class method
can be defined outside of the class and refer to a definition inside
the class with a DW_AT_specification or DW_AT_abstract_origin attribute.

Fixed a case in Thread.cpp where we were looking up info in the frame
when we didn't need to. This was from some changes to support external
editors. Now the info is only looked up if needed.



Modified:
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h
    lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
    lldb/trunk/source/Target/Thread.cpp

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp?rev=137436&r1=137435&r2=137436&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp Fri Aug 12 01:47:54 2011
@@ -851,7 +851,7 @@
                         }
                         else
                         {
-                            if (mangled_cstr && specification_die_offset != DW_INVALID_OFFSET)
+                            if (specification_die_offset != DW_INVALID_OFFSET)
                             {
                                 const DWARFDebugInfoEntry *specification_die = m_dwarf2Data->DebugInfo()->GetDIEPtr (specification_die_offset, NULL);
                                 if (specification_die)

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp?rev=137436&r1=137435&r2=137436&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp Fri Aug 12 01:47:54 2011
@@ -1779,6 +1779,23 @@
     return false;
 }
 
+bool
+DWARFDebugInfoEntry::Contains (const DWARFDebugInfoEntry *die) const
+{
+    if (die)
+    {
+        const dw_offset_t die_offset = die->GetOffset();
+        if (die_offset > GetOffset())
+        {
+            const DWARFDebugInfoEntry *sibling = GetSibling();
+            assert (sibling); // TODO: take this out
+            if (sibling)
+                return die_offset < sibling->GetOffset();
+        }
+    }
+    return false;
+}
+
 //----------------------------------------------------------------------
 // BuildAddressRangeTable
 //----------------------------------------------------------------------

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h?rev=137436&r1=137435&r2=137436&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h Fri Aug 12 01:47:54 2011
@@ -109,6 +109,7 @@
                 {
                 }
 
+    bool        Contains (const DWARFDebugInfoEntry *die) const;
 
     void        BuildAddressRangeTable(
                     SymbolFileDWARF* dwarf2Data,

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=137436&r1=137435&r2=137436&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Fri Aug 12 01:47:54 2011
@@ -664,23 +664,35 @@
     if (die->Tag() != DW_TAG_subprogram)
         return NULL;
 
-    const DWARFDebugInfoEntry *parent_die = die->GetParent();
-    switch (parent_die->Tag())
+    clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die);
+    const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind();
+
+    switch (containing_decl_kind)
     {
-    case DW_TAG_structure_type:
-    case DW_TAG_class_type:
-        // We have methods of a class or struct
-        {
-            Type *class_type = ResolveType (dwarf_cu, parent_die);
-            if (class_type)
-                class_type->GetClangFullType();
-        }
-        break;
+        case clang::Decl::Record:
+        case clang::Decl::CXXRecord:
+        case clang::Decl::ObjCClass:
+        case clang::Decl::ObjCImplementation:
+        case clang::Decl::ObjCInterface:
+            // We have methods of a class or struct
+            {
+                const DWARFDebugInfoEntry *containing_decl_die = m_decl_ctx_to_die[containing_decl_ctx];
+                assert (containing_decl_die);
+                Type *class_type = ResolveType (dwarf_cu, containing_decl_die);
+                if (class_type)
+                    class_type->GetClangFullType();
+                // Make sure the class definition contains the funciton DIE
+                // we wanted to parse. If it does, we are done. Else, we need 
+                // to fall through and parse the function DIE stil...
+                if (containing_decl_die->Contains (die))
+                    break; // DIE has been parsed, we are done
+            }
+            // Fall through...
 
-    default:
-        // Parse the function prototype as a type that can then be added to concrete function instance
-        ParseTypes (sc, dwarf_cu, die, false, false);
-        break;
+        default:
+            // Parse the function prototype as a type that can then be added to concrete function instance
+            ParseTypes (sc, dwarf_cu, die, false, false);
+            break;
     }
     
     //FixupTypes();
@@ -2403,19 +2415,17 @@
 
 
 size_t
-SymbolFileDWARF::ParseChildParameters
-(
-    const SymbolContext& sc,
-    TypeSP& type_sp,
-    DWARFCompileUnit* dwarf_cu,
-    const DWARFDebugInfoEntry *parent_die,
-    bool skip_artificial,
-    bool &is_static,
-    TypeList* type_list,
-    std::vector<clang_type_t>& function_param_types,
-    std::vector<clang::ParmVarDecl*>& function_param_decls,
-    unsigned &type_quals
-)
+SymbolFileDWARF::ParseChildParameters (const SymbolContext& sc,
+                                       clang::DeclContext *containing_decl_ctx,
+                                       TypeSP& type_sp,
+                                       DWARFCompileUnit* dwarf_cu,
+                                       const DWARFDebugInfoEntry *parent_die,
+                                       bool skip_artificial,
+                                       bool &is_static,
+                                       TypeList* type_list,
+                                       std::vector<clang_type_t>& function_param_types,
+                                       std::vector<clang::ParmVarDecl*>& function_param_decls,
+                                       unsigned &type_quals)
 {
     if (parent_die == NULL)
         return 0;
@@ -2493,31 +2503,25 @@
                             // Ugly, but that
                             if (arg_idx == 0)
                             {
-                                const DWARFDebugInfoEntry *grandparent_die = parent_die->GetParent();
-                                if (grandparent_die && (grandparent_die->Tag() == DW_TAG_structure_type || 
-                                                        grandparent_die->Tag() == DW_TAG_class_type))
+                                if (containing_decl_ctx->getDeclKind() == clang::Decl::CXXRecord)
                                 {                                    
-                                    LanguageType language = sc.comp_unit->GetLanguage();
-                                    if (language == eLanguageTypeObjC_plus_plus || language == eLanguageTypeC_plus_plus)
+                                    // Often times compilers omit the "this" name for the
+                                    // specification DIEs, so we can't rely upon the name
+                                    // being in the formal parameter DIE...
+                                    if (name == NULL || ::strcmp(name, "this")==0)
                                     {
-                                        // Often times compilers omit the "this" name for the
-                                        // specification DIEs, so we can't rely upon the name
-                                        // being in the formal parameter DIE...
-                                        if (name == NULL || ::strcmp(name, "this")==0)
-                                        {
-                                            Type *this_type = ResolveTypeUID (param_type_die_offset);
-                                            if (this_type)
-                                            {                              
-                                                uint32_t encoding_mask = this_type->GetEncodingMask();
-                                                if (encoding_mask & Type::eEncodingIsPointerUID)
-                                                {
-                                                    is_static = false;
-                                                    
-                                                    if (encoding_mask & (1u << Type::eEncodingIsConstUID))
-                                                        type_quals |= clang::Qualifiers::Const;
-                                                    if (encoding_mask & (1u << Type::eEncodingIsVolatileUID))
-                                                        type_quals |= clang::Qualifiers::Volatile;
-                                                }
+                                        Type *this_type = ResolveTypeUID (param_type_die_offset);
+                                        if (this_type)
+                                        {                              
+                                            uint32_t encoding_mask = this_type->GetEncodingMask();
+                                            if (encoding_mask & Type::eEncodingIsPointerUID)
+                                            {
+                                                is_static = false;
+                                                
+                                                if (encoding_mask & (1u << Type::eEncodingIsConstUID))
+                                                    type_quals |= clang::Qualifiers::Const;
+                                                if (encoding_mask & (1u << Type::eEncodingIsVolatileUID))
+                                                    type_quals |= clang::Qualifiers::Volatile;
                                             }
                                         }
                                     }
@@ -3620,15 +3624,20 @@
 
                     // Parse the function children for the parameters
                     
-                    const DWARFDebugInfoEntry *class_die = die->GetParent();
-                    if (class_die && (class_die->Tag() == DW_TAG_structure_type || 
-                                      class_die->Tag() == DW_TAG_class_type))
+                    clang::DeclContext *containing_decl_ctx = GetClangDeclContextContainingDIE (dwarf_cu, die);
+                    const clang::Decl::Kind containing_decl_kind = containing_decl_ctx->getDeclKind();
+
+                    const bool is_cxx_method = containing_decl_kind == clang::Decl::CXXRecord;
+                    // Start off static. This will be set to false in ParseChildParameters(...)
+                    // if we find a "this" paramters as the first parameter
+                    if (is_cxx_method)
                         is_static = true;
                     
                     if (die->HasChildren())
                     {
                         bool skip_artificial = true;
                         ParseChildParameters (sc, 
+                                              containing_decl_ctx,
                                               type_sp, 
                                               dwarf_cu, 
                                               die, 
@@ -3650,7 +3659,6 @@
                     if (type_name_cstr)
                     {
                         bool type_handled = false;
-                        const DWARFDebugInfoEntry *parent_die = die->GetParent();
                         if (tag == DW_TAG_subprogram)
                         {
                             if (type_name_cstr[1] == '[' && (type_name_cstr[0] == '-' || type_name_cstr[0] == '+'))
@@ -3698,13 +3706,12 @@
                                     type_handled = objc_method_decl != NULL;
                                 }
                             }
-                            else if (parent_die->Tag() == DW_TAG_class_type ||
-                                     parent_die->Tag() == DW_TAG_structure_type)
+                            else if (is_cxx_method)
                             {
                                 // Look at the parent of this DIE and see if is is
                                 // a class or struct and see if this is actually a
                                 // C++ method
-                                Type *class_type = ResolveType (dwarf_cu, parent_die);
+                                Type *class_type = ResolveType (dwarf_cu, m_decl_ctx_to_die[containing_decl_ctx]);
                                 if (class_type)
                                 {
                                     clang_type_t class_opaque_type = class_type->GetClangForwardType();

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h?rev=137436&r1=137435&r2=137436&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h Fri Aug 12 01:47:54 2011
@@ -278,6 +278,7 @@
 
     size_t                  ParseChildParameters(
                                 const lldb_private::SymbolContext& sc,
+                                clang::DeclContext *containing_decl_ctx,
                                 lldb::TypeSP& type_sp,
                                 DWARFCompileUnit* dwarf_cu,
                                 const DWARFDebugInfoEntry *parent_die,

Modified: lldb/trunk/source/Target/Thread.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Thread.cpp?rev=137436&r1=137435&r2=137436&view=diff
==============================================================================
--- lldb/trunk/source/Target/Thread.cpp (original)
+++ lldb/trunk/source/Target/Thread.cpp Fri Aug 12 01:47:54 2011
@@ -1116,14 +1116,14 @@
     size_t num_frames_shown = 0;
     strm.Indent();
     strm.Printf("%c ", GetProcess().GetThreadList().GetSelectedThread().get() == this ? '*' : ' ');
-
-    StackFrameSP frame_sp = GetStackFrameAtIndex(start_frame);
-    SymbolContext frame_sc(frame_sp->GetSymbolContext (eSymbolContextLineEntry));
-    if (frame_sc.line_entry.line != 0 &&
-        frame_sc.line_entry.file &&
-        GetProcess().GetTarget().GetDebugger().GetUseExternalEditor())
+    if (GetProcess().GetTarget().GetDebugger().GetUseExternalEditor())
     {
-        Host::OpenFileInExternalEditor (frame_sc.line_entry.file, frame_sc.line_entry.line);
+        StackFrameSP frame_sp = GetStackFrameAtIndex(start_frame);
+        SymbolContext frame_sc(frame_sp->GetSymbolContext (eSymbolContextLineEntry));
+        if (frame_sc.line_entry.line != 0 && frame_sc.line_entry.file)
+        {
+            Host::OpenFileInExternalEditor (frame_sc.line_entry.file, frame_sc.line_entry.line);
+        }
     }
     
     DumpUsingSettingsFormat (strm, start_frame);





More information about the lldb-commits mailing list