From a51ed9bb496ce6101468fe9a1027e3aa1c19c143 Mon Sep 17 00:00:00 2001 From: Greg Clayton Date: Thu, 23 Sep 2010 01:09:21 +0000 Subject: [PATCH] Added motheds to C++ classes as we parse them to keep clang happy. llvm-svn: 114616 --- lldb/include/lldb/Core/ClangForward.h | 1 + lldb/include/lldb/Symbol/ClangASTContext.h | 22 ++- lldb/lldb.xcodeproj/project.pbxproj | 12 +- .../Expression/ClangExpressionDeclMap.cpp | 10 +- .../SymbolFile/DWARF/SymbolFileDWARF.cpp | 148 ++++++++++++++++-- .../SymbolFile/DWARF/SymbolFileDWARF.h | 1 + lldb/source/Symbol/ClangASTContext.cpp | 32 ++-- lldb/source/Symbol/UnwindTable.cpp | 17 +- 8 files changed, 193 insertions(+), 50 deletions(-) diff --git a/lldb/include/lldb/Core/ClangForward.h b/lldb/include/lldb/Core/ClangForward.h index 4c6722973fdd..59f24f317f3e 100644 --- a/lldb/include/lldb/Core/ClangForward.h +++ b/lldb/include/lldb/Core/ClangForward.h @@ -37,6 +37,7 @@ namespace clang class CXXBaseSpecifier; class CXXBoolLiteralExpr; class CXXFunctionalCastExpr; + class CXXMethodDecl; class CXXNamedCastExpr; class CXXRecordDecl; class CXXThisExpr; diff --git a/lldb/include/lldb/Symbol/ClangASTContext.h b/lldb/include/lldb/Symbol/ClangASTContext.h index 8c4540c2ce1c..1053147ed2c4 100644 --- a/lldb/include/lldb/Symbol/ClangASTContext.h +++ b/lldb/include/lldb/Symbol/ClangASTContext.h @@ -182,22 +182,28 @@ public: bitfield_bit_size); } - static bool + static clang::CXXMethodDecl * AddMethodToCXXRecordType (clang::ASTContext *ast_context, - void *record_clang_type, + void *record_opaque_type, const char *name, - void *method_type); + void *method_opaque_type, + lldb::AccessType access, + bool is_virtual); - bool - AddMethodToCXXRecordType (void *record_clang_type, + clang::CXXMethodDecl * + AddMethodToCXXRecordType (void *record_opaque_type, const char *name, - void *method_type) + void *method_opaque_type, + lldb::AccessType access, + bool is_virtual) { return ClangASTContext::AddMethodToCXXRecordType(getASTContext(), - record_clang_type, + record_opaque_type, name, - method_type); + method_opaque_type, + access, + is_virtual); } bool diff --git a/lldb/lldb.xcodeproj/project.pbxproj b/lldb/lldb.xcodeproj/project.pbxproj index ddeb11274af6..d21be5479af8 100644 --- a/lldb/lldb.xcodeproj/project.pbxproj +++ b/lldb/lldb.xcodeproj/project.pbxproj @@ -584,6 +584,9 @@ 268F9D54123AA16600B91E9B /* SBSymbolContextList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SBSymbolContextList.cpp; path = source/API/SBSymbolContextList.cpp; sourceTree = ""; }; 269416AD119A024800FF2715 /* CommandObjectTarget.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CommandObjectTarget.cpp; path = source/Commands/CommandObjectTarget.cpp; sourceTree = ""; }; 269416AE119A024800FF2715 /* CommandObjectTarget.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CommandObjectTarget.h; path = source/Commands/CommandObjectTarget.h; sourceTree = ""; }; + 269FF07D12494F7D00225026 /* FuncUnwinders.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FuncUnwinders.h; path = include/lldb/Symbol/FuncUnwinders.h; sourceTree = ""; }; + 269FF07F12494F8E00225026 /* UnwindPlan.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UnwindPlan.h; path = include/lldb/Symbol/UnwindPlan.h; sourceTree = ""; }; + 269FF08112494FC200225026 /* UnwindTable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UnwindTable.h; path = include/lldb/Symbol/UnwindTable.h; sourceTree = ""; }; 26A0604711A5BC7A00F75969 /* Baton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Baton.h; path = include/lldb/Core/Baton.h; sourceTree = ""; }; 26A0604811A5D03C00F75969 /* Baton.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Baton.cpp; path = source/Core/Baton.cpp; sourceTree = ""; }; 26A3B4AC1181454800381BC2 /* ObjectContainerBSDArchive.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ObjectContainerBSDArchive.cpp; sourceTree = ""; }; @@ -1741,9 +1744,6 @@ 26BC7C4B10F1B6C100F91463 /* Symbol */ = { isa = PBXGroup; children = ( - 961FABB81235DE1600F93A47 /* FuncUnwinders.cpp */, - 961FABB91235DE1600F93A47 /* UnwindPlan.cpp */, - 961FABBA1235DE1600F93A47 /* UnwindTable.cpp */, 26BC7C5510F1B6E900F91463 /* Block.h */, 26BC7F1310F1B8EC00F91463 /* Block.cpp */, 26BC7C5610F1B6E900F91463 /* ClangASTContext.h */, @@ -1758,6 +1758,8 @@ 26BC7F1710F1B8EC00F91463 /* DWARFCallFrameInfo.cpp */, 26BC7C5A10F1B6E900F91463 /* Function.h */, 26BC7F1810F1B8EC00F91463 /* Function.cpp */, + 269FF07D12494F7D00225026 /* FuncUnwinders.h */, + 961FABB81235DE1600F93A47 /* FuncUnwinders.cpp */, 26BC7C5B10F1B6E900F91463 /* LineEntry.h */, 26BC7F1910F1B8EC00F91463 /* LineEntry.cpp */, 26BC7C5C10F1B6E900F91463 /* LineTable.h */, @@ -1781,6 +1783,10 @@ 26BC7F2010F1B8EC00F91463 /* Type.cpp */, 26BC7C6610F1B6E900F91463 /* TypeList.h */, 26BC7F2110F1B8EC00F91463 /* TypeList.cpp */, + 269FF07F12494F8E00225026 /* UnwindPlan.h */, + 961FABB91235DE1600F93A47 /* UnwindPlan.cpp */, + 269FF08112494FC200225026 /* UnwindTable.h */, + 961FABBA1235DE1600F93A47 /* UnwindTable.cpp */, 26BC7C6710F1B6E900F91463 /* Variable.h */, 26BC7F2210F1B8EC00F91463 /* Variable.cpp */, 26BC7C6810F1B6E900F91463 /* VariableList.h */, diff --git a/lldb/source/Expression/ClangExpressionDeclMap.cpp b/lldb/source/Expression/ClangExpressionDeclMap.cpp index 662f1539d939..bed235241ee5 100644 --- a/lldb/source/Expression/ClangExpressionDeclMap.cpp +++ b/lldb/source/Expression/ClangExpressionDeclMap.cpp @@ -1205,10 +1205,12 @@ ClangExpressionDeclMap::AddOneType(NameSearchContext &context, false, ClangASTContext::GetTypeQualifiers(copied_type)); - ClangASTContext::AddMethodToCXXRecordType(parser_ast_context, - copied_type, - "___clang_expr", - method_type); + ClangASTContext::AddMethodToCXXRecordType (parser_ast_context, + copied_type, + "___clang_expr", + method_type, + lldb::eAccessPublic, + false); } context.AddTypeDecl(copied_type); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp index 7aa203dc92dd..b3199ccfe576 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -1108,18 +1108,133 @@ SymbolFileDWARF::ParseChildMembers case DW_TAG_subprogram: { + DWARFDebugInfoEntry::Attributes attributes; is_a_class = true; if (default_accessibility == eAccessNone) default_accessibility = eAccessPrivate; - // TODO: implement DW_TAG_subprogram type parsing -// UserDefTypeChildInfo method_info(die->GetOffset()); -// -// FunctionSP func_sp (sc.comp_unit->FindFunctionByUID (die->GetOffset())); -// if (func_sp.get() == NULL) -// ParseCompileUnitFunction(sc, dwarf_cu, die); -// -// method_info.SetEncodingTypeUID(die->GetOffset()); -// struct_udt->AddMethod(method_info); + + //printf("0x%8.8x: %s (ParesTypes)\n", die->GetOffset(), DW_TAG_value_to_name(tag)); + // Set a bit that lets us know that we are currently parsing this + const_cast(die)->SetUserData(DIE_IS_BEING_PARSED); + + const char *mangled = NULL; + dw_offset_t type_die_offset = DW_INVALID_OFFSET; + Declaration decl; + bool is_variadic = false; + bool is_inline = false; + bool is_virtual = false; + unsigned type_quals = 0; + AccessType accessibility = default_accessibility; + + clang::FunctionDecl::StorageClass storage = clang::FunctionDecl::None;//, Extern, Static, PrivateExtern + const char *type_name_cstr = NULL; + ConstString type_name_dbstr; + + + const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes); + if (num_attributes > 0) + { + uint32_t i; + for (i=0; iGetSupportFiles().GetFileSpecAtIndex(form_value.Unsigned())); break; + case DW_AT_decl_line: decl.SetLine(form_value.Unsigned()); break; + case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; + case DW_AT_name: + type_name_cstr = form_value.AsCString(&get_debug_str_data()); + break; + + case DW_AT_MIPS_linkage_name: mangled = form_value.AsCString(&get_debug_str_data()); break; + case DW_AT_type: type_die_offset = form_value.Reference(dwarf_cu); break; + case DW_AT_accessibility: accessibility = DW_ACCESS_to_AccessType(form_value.Unsigned()); break; + //case DW_AT_declaration: is_forward_declaration = form_value.Unsigned() != 0; break; + case DW_AT_external: + if (form_value.Unsigned()) + { + if (storage == clang::FunctionDecl::None) + storage = clang::FunctionDecl::Extern; + else + storage = clang::FunctionDecl::PrivateExtern; + } + break; + case DW_AT_inline: + is_inline = form_value.Unsigned() != 0; + break; + + + case DW_AT_virtuality: + is_virtual = form_value.Unsigned() != 0; + break; + + case DW_AT_allocated: + case DW_AT_associated: + case DW_AT_address_class: + case DW_AT_artificial: + case DW_AT_calling_convention: + case DW_AT_data_location: + case DW_AT_elemental: + case DW_AT_entry_pc: + case DW_AT_explicit: + case DW_AT_frame_base: + case DW_AT_high_pc: + case DW_AT_low_pc: + case DW_AT_object_pointer: + case DW_AT_prototyped: + case DW_AT_pure: + case DW_AT_ranges: + case DW_AT_recursive: + case DW_AT_return_addr: + case DW_AT_segment: + case DW_AT_specification: + case DW_AT_start_scope: + case DW_AT_static_link: + case DW_AT_trampoline: + case DW_AT_visibility: + case DW_AT_vtable_elem_location: + case DW_AT_abstract_origin: + case DW_AT_description: + case DW_AT_sibling: + break; + } + } + } + + void *return_clang_type = NULL; + Type *func_type = ResolveTypeUID(type_die_offset); + if (func_type) + return_clang_type = func_type->GetOpaqueClangQualType(); + else + return_clang_type = type_list->GetClangASTContext().GetBuiltInType_void(); + + std::vector function_param_types; + std::vector function_param_decls; + + // Parse the function children for the parameters + bool skip_artificial = true; + + ParseChildParameters (sc, type_sp, dwarf_cu, die, skip_artificial, type_list, function_param_types, function_param_decls); + + void *method_function_proto = type_list->GetClangASTContext().CreateFunctionType (return_clang_type, &function_param_types[0], function_param_types.size(), is_variadic, type_quals); + if (type_name_cstr) + { + clang::CXXMethodDecl *method_decl = type_list->GetClangASTContext().AddMethodToCXXRecordType (class_clang_type, + type_name_cstr, + method_function_proto, + accessibility, + is_virtual); + assert (method_decl); + //m_die_to_decl_ctx[die] = method_decl; + } + + const_cast(die)->SetUserData(type_sp.get()); + assert(type_sp.get()); + } } break; @@ -1913,6 +2028,7 @@ SymbolFileDWARF::ParseChildParameters TypeSP& type_sp, const DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *parent_die, + bool skip_artificial, TypeList* type_list, std::vector& function_param_types, std::vector& function_param_decls @@ -1939,6 +2055,7 @@ SymbolFileDWARF::ParseChildParameters const char *name = NULL; Declaration decl; dw_offset_t param_type_die_offset = DW_INVALID_OFFSET; + bool is_artificial = false; // one of None, Auto, Register, Extern, Static, PrivateExtern clang::VarDecl::StorageClass storage = clang::VarDecl::None; @@ -1956,6 +2073,7 @@ SymbolFileDWARF::ParseChildParameters case DW_AT_decl_column: decl.SetColumn(form_value.Unsigned()); break; case DW_AT_name: name = form_value.AsCString(&get_debug_str_data()); break; case DW_AT_type: param_type_die_offset = form_value.Reference(dwarf_cu); break; + case DW_AT_artificial: is_artificial = form_value.Unsigned() != 0; break; case DW_AT_location: // if (form_value.BlockData()) // { @@ -1967,7 +2085,6 @@ SymbolFileDWARF::ParseChildParameters // { // } // break; - case DW_AT_artificial: case DW_AT_const_value: case DW_AT_default_value: case DW_AT_description: @@ -1982,6 +2099,10 @@ SymbolFileDWARF::ParseChildParameters } } } + + if (skip_artificial && is_artificial) + continue; + Type *dc_type = ResolveTypeUID(param_type_die_offset); if (dc_type) { @@ -2717,7 +2838,7 @@ SymbolFileDWARF::ParseType(const SymbolContext& sc, const DWARFCompileUnit* dwar const char *mangled = NULL; dw_offset_t type_die_offset = DW_INVALID_OFFSET; Declaration decl; - bool isVariadic = false; + bool is_variadic = false; bool is_inline = false; unsigned type_quals = 0; clang::FunctionDecl::StorageClass storage = clang::FunctionDecl::None;//, Extern, Static, PrivateExtern @@ -2805,9 +2926,10 @@ SymbolFileDWARF::ParseType(const SymbolContext& sc, const DWARFCompileUnit* dwar std::vector function_param_decls; // Parse the function children for the parameters - ParseChildParameters(sc, type_sp, dwarf_cu, die, type_list, function_param_types, function_param_decls); + bool skip_artificial = false; + ParseChildParameters(sc, type_sp, dwarf_cu, die, skip_artificial, type_list, function_param_types, function_param_decls); - clang_type = type_list->GetClangASTContext().CreateFunctionType (return_clang_type, &function_param_types[0], function_param_types.size(), isVariadic, type_quals); + clang_type = type_list->GetClangASTContext().CreateFunctionType (return_clang_type, &function_param_types[0], function_param_types.size(), is_variadic, type_quals); if (type_name_cstr) { clang::FunctionDecl *function_decl = type_list->GetClangASTContext().CreateFunctionDeclaration (type_name_cstr, clang_type, storage, is_inline); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h index e901c7b3df8e..8b9906ec1e4e 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h @@ -248,6 +248,7 @@ protected: lldb::TypeSP& type_sp, const DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *parent_die, + bool skip_artificial, lldb_private::TypeList* type_list, std::vector& function_args, std::vector& function_param_decls); diff --git a/lldb/source/Symbol/ClangASTContext.cpp b/lldb/source/Symbol/ClangASTContext.cpp index 66b129dfb4d7..f9d85ac1100c 100644 --- a/lldb/source/Symbol/ClangASTContext.cpp +++ b/lldb/source/Symbol/ClangASTContext.cpp @@ -803,14 +803,16 @@ ClangASTContext::CreateRecordType (const char *name, int kind, DeclContext *decl return ast_context->getTagDeclType(decl).getAsOpaquePtr(); } -bool +CXXMethodDecl * ClangASTContext::AddMethodToCXXRecordType ( - clang::ASTContext *ast_context, - void *record_opaque_type, - const char *name, - void *method_opaque_type - ) + clang::ASTContext *ast_context, + void *record_opaque_type, + const char *name, + void *method_opaque_type, + lldb::AccessType access, + bool is_virtual +) { if (!record_opaque_type || !method_opaque_type || !name) return false; @@ -825,22 +827,22 @@ ClangASTContext::AddMethodToCXXRecordType clang::Type *record_type(record_qual_type.getTypePtr()); if (!record_type) - return false; + return NULL; RecordType *record_recty(dyn_cast(record_type)); if (!record_recty) - return false; + return NULL; RecordDecl *record_decl = record_recty->getDecl(); if (!record_decl) - return false; + return NULL; CXXRecordDecl *cxx_record_decl = dyn_cast(record_decl); if (!cxx_record_decl) - return false; + return NULL; QualType method_qual_type(QualType::getFromOpaquePtr(method_opaque_type)); @@ -851,17 +853,19 @@ ClangASTContext::AddMethodToCXXRecordType method_qual_type, NULL); + cxx_method_decl->setAccess (ConvertAccessTypeToAccessSpecifier (access)); + cxx_method_decl->setVirtualAsWritten (is_virtual); + // Populate the method decl with parameter decls - clang::Type *method_type(method_qual_type.getTypePtr()); if (!method_type) - return false; + return NULL; FunctionProtoType *method_funprototy(dyn_cast(method_type)); if (!method_funprototy) - return false; + return NULL; unsigned int num_params = method_funprototy->getNumArgs(); @@ -886,7 +890,7 @@ ClangASTContext::AddMethodToCXXRecordType cxx_record_decl->addDecl(cxx_method_decl); - return true; + return cxx_method_decl; } bool diff --git a/lldb/source/Symbol/UnwindTable.cpp b/lldb/source/Symbol/UnwindTable.cpp index dcab19333750..183e2312ba7c 100644 --- a/lldb/source/Symbol/UnwindTable.cpp +++ b/lldb/source/Symbol/UnwindTable.cpp @@ -7,18 +7,19 @@ // //===----------------------------------------------------------------------===// -#include "lldb/Symbol/ObjectFile.h" +#include "lldb/Symbol/UnwindTable.h" +#include + +#include "lldb/lldb-forward.h" + +#include "lldb/Core/Module.h" +#include "lldb/Core/Section.h" +#include "lldb/Symbol/ObjectFile.h" #include "lldb/Symbol/FuncUnwinders.h" #include "lldb/Symbol/SymbolContext.h" -#include "lldb/Core/Section.h" -#include "lldb/Core/Module.h" -#include "lldb/lldb-forward.h" -#include "lldb/Utility/UnwindAssemblyProfiler.h" #include "lldb/Symbol/DWARFCallFrameInfo.h" - -#include "lldb/Symbol/UnwindTable.h" -#include +#include "lldb/Utility/UnwindAssemblyProfiler.h" // There is one UnwindTable object per ObjectFile. // It contains a list of Unwind objects -- one per function, populated lazily -- for the ObjectFile.